[英]SeedStack “persistence.xml” not found using JPA add-on
I am setting up a SeedStack batch application and I am trying to use JPA without persistence.xml, but automatic JPA detection classes. 我正在设置一个SeedStack批处理应用程序,并且尝试使用不带persistence.xml的JPA,而是使用自动JPA检测类。
However, I had theses exceptions: 但是,我有以下例外:
HHH000318: Could not find any META-INF/persistence.xml file in the classpath
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named myUnit
I have this properties in application.yaml: 我在application.yaml中具有以下属性:
# This configuration file can override main configuration for integration tests
jdbc:
datasources:
myDatasource:
provider: org.seedstack.jdbc.internal.datasource.HikariDataSourceProvider
url: jdbc:postgresql://localhost:5432/CNVT
user: postgres
password : admin
jpa:
units:
myUnit:
properties:
hibernate.dialect: org.hibernate.dialect.PostgreSQLDialect
hibernate.hbm2ddl.auto: update
classes:
org:
generated:
project:
domain:
model:
jpaUnit: myUnit
Also, when I add a persistence.xml, the JPA unit is created: 另外,当我添加persistence.xml时,将创建JPA单元:
o.h.e.t.j.p.i.JtaPlatformInitiator HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
org.seedstack.jpa.internal.JpaPlugin Creating JPA unit myUnit from persistence.xml
org.seedstack.jpa.internal.JpaPlugin Created 1 JPA unit(s)
But, I had this exception: 但是,我有一个例外:
org.seedstack.seed.SeedException: [SPRING] No spring entitymanager
I would like to use JPA with SeedStack properly without having to do a persistence.xml. 我想将JPA与SeedStack一起正确使用,而不必执行persistence.xml。
Look at the example here , your SeedStack JPA configuration is missing the reference to the datasource: 在此处查看示例,您的SeedStack JPA配置缺少对数据源的引用:
jpa:
units:
myUnit:
datasource: myDatasource
properties:
hibernate.dialect: org.hibernate.dialect.PostgreSQLDialect
hibernate.hbm2ddl.auto: update
The absence or presence of the datasource
attribute is what makes SeedStack choose between persistence.xml
based config or not (but it's not obvious). 缺少
datasource
属性是使SeedStack在是否基于persistence.xml
的配置之间进行选择的原因(但这并不明显)。
In addition, the "No spring entitymanager" exception makes me think you have configured SeedStack to let Spring manage the JPA transactions (using spring.manageJpa
config attribute). 另外,“ No springEntitymanager”异常使我认为您已经配置了SeedStack以让Spring管理JPA事务(使用
spring.manageJpa
config属性)。 If that's the case, it's in contradiction with your SeedStack JPA settings. 如果真是这样,那就与您的SeedStack JPA设置相矛盾。
In a SeedStack/Spring batch, you can either choose to: 在SeedStack / Spring批处理中,您可以选择:
spring.manageJpa
to true. spring.manageJpa
设置为true。 This will allow SeedStack-managed code to use the Spring-configured JPA transaction manager. Letting Spring manage JPA provides better performance during a Spring batch job, so I recommend the second option (but for batch jobs only). 让Spring管理JPA可以在Spring批处理作业中提供更好的性能,因此我建议使用第二种选择(但仅适用于批处理作业)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.