-->
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.  [ 7 posts ] 
Author Message
 Post subject: How to save a complex object
PostPosted: Wed Jan 14, 2004 9:31 am 
Newbie

Joined: Fri Jan 09, 2004 9:55 am
Posts: 10
Location: Rutland, UK
Dear all

I have created an object as follows:

Code:
Business
   +-- Contact
          +-- Address
          +-- TelephoneNumber


I want to be able to update just the contact details (e.g. forename), but don't know how to do that without updating the whole complex object.

If anyone could shed some light on what route I need to take I would be very grateful,

nick.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2004 9:34 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Code:
Session session = sessionFactory.openSession();
Buisness buisness = session.load(Business.class, id);
buisness.getContact().getAdresss().setStreet("Something");
session.flush();
session.close();


Top
 Profile  
 
 Post subject: Getting "Object already associated with this id"
PostPosted: Thu Jan 15, 2004 5:16 am 
Newbie

Joined: Fri Jan 09, 2004 9:55 am
Posts: 10
Location: Rutland, UK
I'm using struts and so, trying to implement your solution, I've got the desired object back from the session (using inbuilt functionality), altered it to my requirements and then tried to pass it back to the save method.

All works well until it finds an 'old' version of the object already in the session (I assume from when I got the object back in the first place).

I've hit this problem from two seperate paths now and I really need to find a solution in order to proceed with my project.

I'm sure I cannot be the only person who has had this problem.

Any help would be gratefully received.

Nick.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2004 5:29 am 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Use Session.update() or Session.saveOrUpdate() with an existing object.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2004 5:33 am 
Newbie

Joined: Fri Jan 09, 2004 9:55 am
Posts: 10
Location: Rutland, UK
I am using saveOrUpdate, that is where the error popped up.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2004 5:35 am 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Sigh...ignore me. It's 4am here. :P


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 15, 2004 9:53 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
If you have the object allready associated with the session, you don't need to do a saveOrUpdate, automatic dirty checking should automatically save the object on flush


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.