【问题标题】:Exception using Play framework JPA updating unique constraint field使用 Play 框架 JPA 更新唯一约束字段的异常
【发布时间】:2015-08-26 16:04:25
【问题描述】:

从唯一字段 (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]

【问题讨论】:

    标签: java hibernate jpa playframework


    【解决方案1】:

    您应该在删除后立即刷新会话,以免休眠选择 SQL 语句执行顺序。

    【讨论】:

    • 您可以将响应标记为正确的。谢谢。
    猜你喜欢
    • 1970-01-01
    • 2015-12-17
    • 2011-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多