0
從一個獨特的領域(MySQL的)我需要在一個事務中再次重命名 剩下的值刪除1個值後: 代碼:異常使用播放框架JPA更新唯一約束場
JPA.withTransaction(new Callback0() {
@Override
public void invoke() throws Throwable {
obj.removeDevice(deviceID);
// if I put removeDevice in different transaction it works !
// but can cause integrity problem i case of failure
obj.changeTemporalDevices(...);
obj.reCalcDevicesNames(...);
obj.saveDevices(....);
}
});
這似乎JPA不會「看見」的值已經在一個事務中被刪除,我得到了下面的異常:
[ERROR] org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Duplicate entry 'aaa2r28c011' for key 'name_device_UNIQUE'
[ERROR] application - javax.persistence.RollbackException: Error while committing the transaction
java.lang.RuntimeException: javax.persistence.RollbackException: Error while committing the transaction
at play.db.jpa.JPA.withTransaction(JPA.java:111) ~[play-java-jpa_2.10-2.3.8.jar:2.3.8]
謝謝! JPA.em()平齊();解決問題 –
然後您可以將響應標記爲正確的響應。謝謝。 – Franck