-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Setting entities' associations without actually loading them
PostPosted: Fri Oct 21, 2005 5:25 pm 
Newbie

Joined: Fri Oct 21, 2005 5:10 pm
Posts: 1
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.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 24, 2005 5:46 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
do something else
Actor actor = (Actor) session.load(Actor.class, new Integer(1));
or
Actor actor = entityManager.getReference(Actor.class, new Integer(1));

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.