我有以下触发器,可确保只有一条记录具有字段 DEFAULTCARD=1
create trigger TRG_U_XSTRDCRD
after update on XSTOREDCARD referencing new as N old as O
for each row mode db2sql
begin atomic
if N.DEFAULTCARD = 1 then
update XSTOREDCARD
set DEFAULTCARD = 0
where USERS_ID = N.USERS_ID and ID <> N.ID;
end if;
end@
我还想确保只有一条记录的 EBACTIVE 字段值为 1,所以我尝试了这个。
create trigger TRG_U_XSTRDCRD
after update on XSTOREDCARD referencing new as N old as O
for each row mode db2sql
begin atomic
if N.DEFAULTCARD = 1 then
update XSTOREDCARD
set DEFAULTCARD = 0
where USERS_ID = N.USERS_ID and ID <> N.ID;
end if;
if N.EBACTIVE = 1 then
update XSTOREDCARD
set EBACTIVE = 0
where USERS_ID = N.USERS_ID and ID <> N.ID;
end if;
end@
但它不起作用,它在更新几分钟后导致超时:
Caused by: com.ibm.db2.jcc.b.SqlException: DB2 SQL error: SQLCODE: -101, SQLSTATE: 54001, SQLERRMC: null
at com.ibm.db2.jcc.b.zc.e(zc.java:1606)
at com.ibm.db2.jcc.b.zc.a(zc.java:1206)
at com.ibm.db2.jcc.a.db.h(db.java:149)
at com.ibm.db2.jcc.a.db.a(db.java:43)
at com.ibm.db2.jcc.a.r.a(r.java:30)
at com.ibm.db2.jcc.a.sb.g(sb.java:152)
at com.ibm.db2.jcc.b.zc.n(zc.java:1186)
at com.ibm.db2.jcc.b.ad.db(ad.java:1761)
at com.ibm.db2.jcc.b.ad.d(ad.java:2203)
at com.ibm.db2.jcc.b.ad.V(ad.java:521)
at com.ibm.db2.jcc.b.ad.executeUpdate(ad.java:504)
at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2595)
... 19 more
关于什么是错的或如何做的任何建议?
干杯! NFV