-->
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: Updating a foreign key column
PostPosted: Sun Nov 30, 2008 11:21 am 
Newbie

Joined: Sun Nov 23, 2008 2:32 pm
Posts: 4
Hi,

I'm new to Hibernate, I have a 1 to 1 relationship set up between two objects (tables).

So the table generated just uses a foreign id column with the id of the other object, which is pretty much what I expected. But the Java object has an instance variable of the type of the other object. What I want to know is what's the best way to update this. I tried just changing the ID of the associated object and calling save but I get this error:

"a different object with the same identifier value was already associated with the session"

My first thought to get the other object and set that to the first object but this seems like a lot of overhead for something simple. Is there an better way?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 01, 2008 4:41 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Quote:
My first thought to get the other object and set that to the first object but this seems like a lot of overhead for something simple. Is there an better way?


This is the correct way and there is nothing wrong or bad with it.


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.