creating new instances of model objects

I was trying something out today and discovered something that doesn’t seem to be working right, or maybe it is and I am doing it wrong.

I have a handler, and two model objects. Nothing out of the ordinary, one model object is a singleton and the other is a transient.

When do something like this in my handler, I am getting strange results.

property name=“myTest” inject

inside the handler I am also doing this.

myTest2 = getModel(“myTest1”);

myTest3 = getModel(“myTest1”);

What seems to be happening is that the singleton is being ignored, for example if I then do this


I find that the second instantiated model is actually a copy of the first, am I right to expect that both myTest2 and myTest3 are actual transients rather than singletons?

Andrew Scott

Hi Andrew,

it depends on how your models are set up and without this information it’s hard to answer your question. In general your model “myTest” will have the same scope as the target object, because of the scope widening effect and myTest2 and myTest3 should be transient objects if they don’t have any special annotations.

Yeah that is what I know, or thought.

Problem was my code wasn’t seeing that behavior, that was until I realised that the model was a singleton and why it was cached.