Now, I have a new problem for saveOrUpdate() method. This time, I want use saveOrUpdate() to insert into table.
Code:
Transaction tranc = session.beginTransaction();
session.saveOrUpdate(gp1);
System.out.println("go to here");
tranc.commit();
The "go to here" can be printout. However, when I do commit, it produced the following exception:
[java] org.hibernate.StaleStateException: Batch update returned unexpected row count from updat
e [0]; actual row count: 0; expected: 1
[java] at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:6
1)
[java] at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:
46)
[java] at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:24)
[java] at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersi
ster.java:2353)
[java] at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEnt
ityPersister.java:2257)
[java] at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersi
ster.java:2557)
[java] at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:92)
[java] at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
[java] at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
[java] at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
[java] at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractF
lushingEventListener.java:298)
[java] at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListen
er.java:27)
[java] at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
[java] at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
[java] at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
[java] at com.bear.test1.QueryTest.initDirectedGraph(Unknown Source)
[java] at com.bear.test1.QueryTest.main(Unknown Source)
[java] Exception in thread "main"
[java] Java Result: 1
Why I can not use saveOrUpdate()? The id for the mapping xml, I set unsaved-value="null". Is it right?