表格定义:
create table foo
(
foo_id integer not null,
order_id integer not null,
constraint foo_pk primary key (foo_id),
constraint foo_ak unique (order_id) deferrable
);
生成违规的SQL并查看控制台上显示的错误:
set constraint foo_ak deferred;
insert into foo values (1, 1);
insert into foo values (2, 1);
set constraint foo_ak immediate; -- Will rollback and display error
JPA尝试重新排序无状态会话Bean中的foo实体集合:
public void edit(List<Foo> foos) {
Query deferred = em.createNativeQuery("set constraint foo_ak deferred");
Query immediate = em.createNativeQuery("set constraint foo_ak immediate");
deferred.executeUpdate(); // This works
for(Foo f: foos) {
em.merge(f); // This works too
}
immediate.executeUpdate(); // Hang with no output!
// Note: if I comment out above line the transaction may
// be silently rolled back on deferred constraint violation
}
答案 0 :(得分:1)
问题可以在语句缓存和应用服务器事务策略中。
尝试:
和/或