0

I have one to many relationship in hibernate tables.and Line table i kept as Collections Set that is

@OneToMany(cascade = CascadeType.ALL, fetch =   FetchType.EAGER)
@JoinColumn(name = "JOBCARD_ID")
private Set<ItemDetails> itemDetailsList;

When i update all header and line records ,some records has been deleted becasuse set removed duplicate records before update.

My problem is how to avoid this deletion when updating records. please do the needful.

Dhinesh
  • 1
  • 5
  • header? line? what you described does not match your code. Can you be more clear on what you have been doing? – Adrian Shum Jul 20 '16 at 10:34
  • I have one many relationship in my tables.So i have set as Line records mentioned above in the entity.When i update all tables,Due to Set Duplicate entries deleted and new entry will update.I dont need to delete duplicate entries in my table. – Dhinesh Jul 20 '16 at 11:29
  • What you just said is just as vague as what you have in your question. Can you use proper terminology instead of making up terms? "Update all table"? What does it mean here in this context? Show us what you have done in short and clear code snippets – Adrian Shum Jul 20 '16 at 11:34
  • In hibernate We can update all header and line records in a single query.for example session.update(vehicledetails). In vehicle details entity i have mentioned below line table @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @JoinColumn(name = "JOBCARD_ID") private Set itemDetailsList; – Dhinesh Jul 20 '16 at 11:39
  • That's what I said: there is nothing called "header" and "line" in context of Hibernate. Don't come up with your own terminology. Even using "parent-child" is more descriptive. And, hibernate is an ORM tools and we are seeing things as entities, not table. What you are trying to do is merging detached/transient entities (not very accurate, just brief idea). (It is not QUERY!) and it is usually NOT the way we use Hibernate. It seems to me that you are lacking a lot of basic concept on Hibernate and you are using it in way that it is not good at. Learn more before you jump into hibernate – Adrian Shum Jul 20 '16 at 11:52
  • as a thought, if you are trying not to remove old rows of data related to the one to many relationship, you can try to add orphanRemoval = false for e.g. after the FetchType.EAGER like so: @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = false) – ghoulfolk Jul 22 '16 at 07:12

0 Answers0