0
//parent class    
@OneToMany(mappedBy="parentClass",cascade=CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REMOV    CascadeType.REFRESH}, orphanRemoval =false, fetch = FetchType.EAGE    

@CascadeOnDelete
private List<ChildClass> childClass;

//child class

@ManyToOne(cascade={CascadeType.PERSIST,CascadeType.REMOVE,CascadeType.REFRESH})


private ParentClass parentClass;

I am facing some problem in merging.

Sometimes it is working perfectly some time it's not working. For example the first time, I am setting

amount=30 balamount=20 adjamount=10

It is perfectly set. After that I have set

amount=10 balamount=10 adjamount=0

but in database I get

amount=30 balamount=30 adjamount=0

The entity is correctly set. But after committing, the database is not updated correctly.

I am not getting what the problem is. Can you please point out what is the problem in my code?

Pascal Le Merrer
  • 5,883
  • 20
  • 35
  • Improved syntax, grammar and presentation. – Pascal Le Merrer Jan 12 '16 at 13:32
  • `equals()` / `hashcode()` for the mapper-classes are ok? – Gergely Bacso Jan 12 '16 at 13:49
  • You show a ManyToOne and OneToMany mapping but give no clue where and how are the amount, balamount and adjamount fields mapped, how they are being changed and merged. Note that your ManyToOne does not have a cascade merge setting. You should also debug your application to figure out where the balamount=30 is coming from, as that isn't something JPA would just do. – Chris Jan 12 '16 at 15:27
  • thanks for your time and help. In debug also values are setting correctly but in sql queries its setting wrong data. The problem got rectified, I was updating so many entity in single commit. Now I have changed the order of merging and its working fine. – user3682401 Jan 14 '16 at 18:29

0 Answers0