Batch update returned unexpected row count from update

I have the following relationship:

// In A.java class @OneToMany(mappedBy="a", fetch=FetchType.LAZY) @Cascade(CascadeType.SAVE_UPDATE) private List<B> bList; // In B.java class @ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="id_a") @Cascade(CascadeType.SAVE_UPDATE) private A a; 

I get this exception:

 StaleStateException: Batch update returned unexpected row count from update 

When I try to saveOrUpdate entity a after removing b from it.

 // first delete old b record Session session = HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction(); a.getBList().remove(b); b.setA(null); session.delete(b); // session.clear(); // this would solve my problem, but is it correct?? session.getTransaction().commit(); // then insert new b record Session session=HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction(); B b=new B(); a.getBList().add(b); b.setA(a); session.saveOrUpdate(a); session.getTransaction().commit(); // this throw exception 

These two operations, of course, not in the same method, are triggered by the gui event.

Is session.clear real solution? Am I (possibly) wrong?

Removing session.delete(b) solves the "problem" ... so what is the correct way?

+1
java exception hibernate session transactions
source share

No one has answered this question yet.

See similar questions:

7
Refresh OneToMany list after saving an entity in sleep mode

or similar:

125
Hibernate - batch update returned unexpected line count from update: 0 actual number of lines: 0 expected: 1
7
Refresh OneToMany list after saving an entity in sleep mode
6
I get an error with oneToMany association when using annotations with gilead for hibernation through gwt
3
How to ignore a unique violation in inserting a list of objects that conatin a set of objects
3
Hibernate: Why is the FetchType.LAZY-annotated collection property eagerly loading?
3
ManyToMany hibernation with combining table issues when updating
2
Hibernate remove from onetomany
one
Bring the kids from the lazy list to many
one
Why is there 0 ... 1 Relationship to the join table?
0
1: M in sleep mode and cascading operations

All Articles