[英]Spring Data JPA + Hibernate do execute save methods, but don't execute insert/update statements
Issue 问题
The problem is that, at each build of the project with Maven, the build produces randomly a working jar or a broken one. 问题在于,在使用Maven进行的项目的每个构建中,该构建都会随机生成一个工作jar或一个损坏的jar。 Obviously there aren't any changes neither in code or configuration. 显然,代码或配置都没有任何改变。
What I mean with broken? 我的意思是坏了吗?
Usually, each 5/6 builds, 1 working JAR is generated, while 4/5 are broken. 通常,每5/6个构建,生成1个有效的JAR,而4/5被破坏。 The broken and working jars are identical with binary comparison. 破损的罐子和工作罐子与二进制比较相同。
Once a JAR is compiled, if it is broken, each execution will be broken, regardless of how many times it is executed. 编译JAR后,如果JAR被破坏,则每次执行都会被破坏,无论它执行了多少次。 Same goes for the working one. 工作的人也是如此。
What I Already Tried 我已经尝试过的
Configuration 组态
I have a Spring Batch Project, based on Spring Data JPA and Hibernate. 我有一个基于Spring Data JPA和Hibernate的Spring Batch项目。 The batch is executed by a sh file. 批处理由sh文件执行。 As you can see in the configuration, for debug reasons, I have hibernate.show_sql
parameter set to true. 如您在配置中看到的,出于调试原因,我将hibernate.show_sql
参数设置为true。 The database is Oracle 11g. 该数据库是Oracle 11g。
POM: POM:
<properties>
<spring-version>5.1.5.RELEASE</spring-version>
<hibernate-version>5.4.1.Final</hibernate-version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-core</artifactId>
<version>4.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>2.1.5.RELEASE</version>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate-version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate-version}</version>
</dependency>
.....
</dependencies>
Hibernate Properties: 休眠属性:
hibernate.synonyms=true
hibernate.allocationSize=1000
hibernate.order_inserts=true
hibernate.order_updates=true
hibernate.show_sql=true
hibernate.jdbc.batch_versioned_data=true
hibernate.id.new_generator_mappings=true
hibernate.jdbc.batch_size=30
hibernate.generate_statistics=false
Working Log: 工作日志:
2019-06-27 10:42:03.558 [pool-3-thread-19] INFO i.a.n.b.t.XXX (246) - Elaborazione TABLE1 con SEQU: 2071042
Hibernate: select SEQUENCE1.nextval from dual
Hibernate: insert into TABLE2 (........) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: select column1, column2 ... from TABLE3 where condtion
2019-06-27 10:42:03.651 [pool-3-thread-19] INFO i.a.n.b.s.i.BaseOrderServiceImpl (185) - Recuperato record dalla TABLE3 con ID : 2071042
Broken Log: 日志损坏:
2019-06-27 10:42:03.558 [pool-3-thread-19] INFO i.a.n.b.t.XXX (246) - Elaborazione TABLE1 con SEQU: 2071042
Hibernate: select SEQUENCE1.nextval from dual
INSERT MISSING HERE
Hibernate: select column1, column2 ... from TABLE3 where condtion
2019-06-27 10:42:03.651 [pool-3-thread-19] INFO i.a.n.b.s.i.BaseOrderServiceImpl (185) - Recuperato record dalla TABLE3 con ID : 2071042
Call for help: 寻求帮助:
I am building my project multiple times each time I need to deploy it, for months. 每次需要部署该项目时,我都会多次构建该项目,几个月。 I'd like to solve this problem once and for all and I'd appreciate your help. 我想一劳永逸地解决这个问题,感谢您的帮助。
If you need snippet of codes ask me, but generally they are normal save with basic entities, with @Transactional
notation working fine with working JAR. 如果您需要一小段代码,请问我,但通常来说,除了基本实体外,它们都是正常的,@ @Transactional
表示法可以与工作JAR一起正常工作。
Thank you. 谢谢。
Update 更新资料
As suggested I tried to uniform spring and hibernate dependencies to the same version. 如建议的那样,我尝试将spring和hibernate依赖关系统一到同一版本。 The problem is still there. 问题仍然存在。
Update pom 更新pom
<properties>
<spring-version>5.0.12.RELEASE</spring-version>
<hibernate-version>5.2.17.Final</hibernate-version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-core</artifactId>
<version>4.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>2.1.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring-version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.2.17.Final</version>
</dependency>
</dependencies>
I resolved the issue with the following steps: 我通过以下步骤解决了该问题:
These steps resolved the issue. 这些步骤解决了该问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.