hibernate在升级到java11之后生成2个insert而不是update

a6b3iqyw  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(196)

我将maven编译器插件目标和源代码从1.8改为11,从而将我的应用程序迁移到了java11

<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
            <source>11</source>
            <target>11</target>
            <encoding>UTF-8</encoding>
            <compilerArguments>
                <processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
            </compilerArguments>
        </configuration>
    </plugin>
</plugins>

然后添加了所需的依赖项

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
</dependency>
<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
</dependency>

就这样。应用程序加载并在一定程度上工作,但它无法保存实体。失败的代码部分在java8中工作得很好,但在java11中却失败了。
代码是

LoginRequest req = ...;

LoginAttempt la = service.saveLoginAttempt(...); // saveLoginAttempt has transactional annotation
Result result = client.authorize(req);
updateLoginAttempt(result, la); // this method does too

最终,它所做的只是使用 JpaSpecRepository 并调用save方法。在Java8中,没问题,在调用saveLoginAttent之后插入实体,然后在调用updateloginattempt之后通过生成updateSQL来更新实体。
在Java11中,第一次调用什么也不做,在第二次调用save时(在updateloginattemmpt方法中),它生成2个插入,并失败,出现唯一的id冲突异常。。。你知道这是什么吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题