Hi!
I'm trying to save multible objects inside on session.
inside A.hbm.xml file I have defined
Code:
<set name="bs" table="B" inverse="true" cascade="all">
<key column="A_id" />
<one-to-many class="persistence.B" />
</set>
and similarly for class C
in B and C.hbm.xml
Code:
<many-to-one name="a" class="persistence.A" column="A_id"/>
below is the code in class A
Code:
Set<B> bs;
Set<C> cs;
public void save(Session session){
Transaction transaction = session.beginTransaction();
session.save(this);
transaction.commit();
for (B b : bs) {
b.save(session);
}
for (C c : cs) {
c.save(session);
}
}
and blow is the code for class B and C, save-method in both is the same
Code:
public void save(Session) {
Transaction transaction = session.beginTransaction();
session.save(this);
transaction.commit();
}
Hibernate version: 3.2.0 GA
Now I'm getting
Code:
org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:61)
at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:46)
at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:68)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at persistence.A.save(A.java:55)
What is the best solution saving tree of objects?