I was always caught by the error when updating data to a table which have a triger in it,
16:25:22,890 ERROR SessionImpl:2399 - Could not synchronize database state with session
net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:663)
at net.sf.hibernate.persister.EntityPersister.update(EntityPersister.java:623)
at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:52)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2438)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2392)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2260)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at pal.pdm.personnel.base.HibernateExec.updateObjectWithTriger(HibernateExec.java:542)
at pal.pdm.personnel.MainClass.testUpdate(MainClass.java:135)
at pal.pdm.personnel.MainClass.main(MainClass.java:119)
I have tried to use method flush and refresh to solve it, but it failed
session.update(obj);
session.flush();
session.refresh(obj);
session.commit();
The triger is
CREATE TRIGGER [ORG_RESOURCE_update_for_prj] ON dbo.ORG_RESOURCE
FOR UPDATE
AS
DECLARE @old_dev_no as nvarchar(20),
@new_dev_no as nvarchar(20),
@dev_name as nvarchar(50),
@dev_type as nvarchar(256)
--get the old id
SELECT @old_dev_no=del.c_resourceno
FROM deleted del
--get the new id and name
SELECT
@new_dev_no=ins.c_resourceno,
@dev_name=ins.c_resourcename,
@dev_type=ins.c_type
FROM inserted ins
--update task info
UPDATE PRJ_TASKDEVICE SET
devno=@new_dev_no,
taskdevname=@dev_name,
devicetype=@dev_type
where devno=@old_dev_no
help me, thanks :)
I'm sorry, I'm a chinese with poor English
and for the first I come here
please be tolerant to my poor English
|