Can an INITIALLY DEFERRED constraint be defined using a Hibernate annotation?

旧时模样 提交于 2019-12-02 07:13:11

Unfortunately, Hibernate does not have support for deferred constraints. https://hibernate.atlassian.net/browse/HHH-2248

You could try playing with entityManager.flush() method, let's say you have Instruments with names inst1 and inst2:

Instrument inst1 = entityManager.find(Instrument.class, 1);
// change name of first Instrument to some random one
inst1.setName("inst3");
entityManager.flush();
Instrument inst2 = entityManager.find(Instrument.class, 2);
inst2.setName("inst1");
entityManager.flush();
inst1.setName("inst2");

Alternatively you could get the entities from DB, delete them from DB, perform flush and persist updated entities. This way you don't have to make up the third name.

Not sure about performance effect of those solutions, you have to figure out yourself.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!