测试保存时,报错a different object with the same identifier value was already associated with the session
然后我自己百度,有人说用merge()方法就可以解决,然而我使用之后又有心得错误。
INFO: HHH000232: Schema update complete
Hibernate:
select
max(GID)
from
gread
Hibernate:
select
students0_.STUID as STUID1_0_0_,
students0_.STUNAME as STUNAME2_0_0_,
students0_.STUADDR as STUADDR3_0_0_,
students0_.STUPHONE as STUPHONE4_0_0_
from
STUDENTS students0_
where
students0_.STUID=?
Hibernate:
insert
into
gread
(GNAME, GDESC, GID)
values
(?, ?, ?)
Hibernate:
insert
into
STUDENTS
(STUNAME, STUADDR, STUPHONE, STUID)
values
(?, ?, ?, ?)
Hibernate:
update
STUDENTS
set
STUNAME=?,
STUADDR=?,
STUPHONE=?
where
STUID=?
Exception in thread "main" 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:81)
at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:73)
at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:59)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3224)
at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:3126)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:3456)
at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:140)
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:377)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:369)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:287)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:339)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1234)
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:404)
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:175)
at com.py4g.test.Test.add(Test.java:33)
at com.py4g.test.Test.main(Test.java:12)