Hi everyone,
Foremost my setup: - I have 2 Classes - Person(entity) and Address(component), in which a Person object can have 1 or more Address objects - Person-to-Address association within Person class @ElementCollection(fetch = FetchType.EAGER) @JoinTable(name = "T_Address", joinColumns = @JoinColumn(name = "ORDER_ID")) public List<Address> getAddresses() { return addresses; } - Address-to-Person association within Address class not needed since I do not need any address-to-person reference
My current Situation: Whenever I modify an address field or add/delete an address object within the address List in a person object, Hibernate seems to first delete all address objects associated with this person, and afterwards it has them inserted again.
In the Code below I only modified the street of an address object; Hibernate deleted all Adress objects and subsequently inserted all 3 Address objects into Address table again:
Hibernate: delete from T_ADDRESS where PERSON_ID=? Hibernate: insert into T_ADDRESS (PERSON_ID, CREATED, STREET, ZIP, COUNTRY) values (?, ?, ?, ?, ?) Hibernate: insert into T_ADDRESS (PERSON_ID, CREATED, STREET, ZIP, COUNTRY) values (?, ?, ?, ?, ?) Hibernate: insert into T_ADDRESS (PERSON_ID, CREATED, STREET, ZIP, COUNTRY) values (?, ?, ?, ?, ?)
My Question: Is there any possibility to make Hibernate only delete/modify/add the affected address objectwithin the address list of the person object? For I hope the solution will improve the performance of my written program tremendously.
Thank you for your time and help. I really appreciate it! Charlie
|