Before I post lots code, I just want confirmation that my assumptions are correct about how hibernate and/or jpa deals with detached and reattached objects.
Using hibernate 3.0.2 on jboss 4.0.2 I was successfully loading a form representing a university, with a UniversityType reference object selectable in a list, and saving the University on a form submit. It could be either a brand new university or a modified one. Either way I called saveOrUpdate on it and it would work as expected.
Now I am getting a TransientObjectException on the UniversityType. I am guessing that it is because the UniversityType objects were loaded on a separate session when loading the form, and then a new session was opened when the form was submitted to save the University object.
I believe it worked before because hibernate was using unsaved-value attributes on the UniversityType entity and thus it could figure out whether it was supposed to be saved or not. I don't see a related annotation.
So am i correct that the entity manager cannot save an entity that has a reference ManyToOne entity that was loaded from a different session? If that is true, then how would i solve the problem of loading and submitting this university edit form?
If i'm wrong i'll look through my code and narrow down where i went wrong.
Thanks for reading,
k
|