Hibernate version:
3.1beta1
Mapping documents:
<class name="eg.Actor" table="ACTORS">
<id name="id" column="ID"><generator class="native" /></id>
<property name="name" column="NAME" />
</class>
<class name="eg.ActorRole" table="ACTOR_ROLES">
<id name="id" column="ID"><generator class="native" /></id>
<property name="name" column="NAME" />
<many-to-one name="actor" column="ACTOR_ID" />
</class>
Problem:
Hi, I've got a very weird problem... Until I switched to annotations mapping, I was able to set an entity's associations without pre-loading these by creating empty objects with the right id.
For example, if I want to create a new ActorRole entity linked to the Actor entity #1, just doing the following would be enough:
Code:
ActorRole actorRole = new ActorRole();
actorRole.setName("John");
actorRole.setActor(new Actor());
actorRole.getActor().setId(1L);
session.save(actorRole);
This would result in a new ActorRole record persisted with the correct FK in the ACTOR_ID column (#1).
Now that I switched to annotations, the same code would get me an exception:
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: eg.Actor
Does anybody see what could be wrong?
Thanks a lot,
Xavier.