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.
|