使用Play框架JPA更新唯一约束字段的异常

时间:2015-08-26 16:04:25

标签: java hibernate jpa playframework

从唯一字段(Mysql)中删除1个值后,我需要重命名 一次交易中的剩余价值: 代码:

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]

0 个答案:

没有答案