-->
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.  [ 1 post ] 
Author Message
 Post subject: How to make collection items persistent?
PostPosted: Wed Sep 01, 2010 1:38 pm 
Newbie

Joined: Wed Sep 01, 2010 1:18 pm
Posts: 3
Hello all,
I am extremely new to Hibernate.

I have a many-to-many relationship called PersonAddressLink between Person and Address entities as follows:
Person(person_id, other attributes) ---PersonAddressLink(person_id,address_id)-----Address(address_id, other attributes)

I was able to successfully map this relationship using Hibernate
in two persistent classes Person and Address. In Person, I have addresses List to store all the associated address of a Person.

I am able to successfully retrieve all the addresses associated with a Person.

In my database, if I want to assign a person to a new address, I would do something like:
update PersonAddressLink set address_id = 'new_address_id' where person_id='person_id' and address_id='old_address_id'

How can I do the same using hibernate? (I will be provided person_id,old_address_id,new_address_id)
I was thinking of doing something like:
- Load Person instance
- Get Address list
- In that Address list, remove old Address using List.remove(oldAddressObject)
- In that Address list, add new Address using List.add(newAddressObject)
- Make the Address list persistent

Can you please suggest how it can be done using hibernate?

Your suggestions would be highly appreciated.

If I make the Address list persistent, then will it automatically update the PersonAddress table in the database?

Thank you very much.


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

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.