mguymon / model-citizen

Annotation based model factory for Java
Apache License 2.0
94 stars 13 forks source link

Constructor callback called multiple times on createModel #10

Closed mttkay closed 11 years ago

mttkay commented 11 years ago

I'm using a constructor callback to generate consecutive model IDs in running order. However, I observed weird jumps between generated IDs. I debugged into the constructor callback and noticed that it's called multiple times for the same call to modelFactory.createModel.

I think a blueprint's constructor callback for the blueprinted model should only be called once per invocation of createModel.

mttkay commented 11 years ago

Looking closer, I think this might be because when using the single argument version of createModel, a default reference model is first created using erector.createNewInstance.

I think if no reference object is supplied, no reference object should be used.

mguymon commented 11 years ago

The way it works right now, the reference model is used to get the values for the newly created model. If a reference is not passed in, one is created. For the ModelFactory to work, it requires an instance of the object to apply the blueprint to.

The ModelFactory could be retooled so that it uses the created model as the reference, if a reference is not passed in.

mttkay commented 11 years ago

Thanks Michael, I might look into this actually.