我正在设置一个SeedStack批处理应用程序,并且尝试使用没有persistence.xml的JPA,但是使用自动JPA检测类。
然而,我有这些例外:
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 我在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此外,当我添加一个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)但是,我有个例外:
org.seedstack.seed.SeedException: [SPRING] No spring entitymanager我想在SeedStack中正确地使用JPA,而不必执行persistence.xml。
发布于 2019-07-22 09:34:32
查看示例这里,您的SeedStack JPA配置缺少对数据源的引用:
jpa:
units:
myUnit:
datasource: myDatasource
properties:
hibernate.dialect: org.hibernate.dialect.PostgreSQLDialect
hibernate.hbm2ddl.auto: updatedatasource属性的缺失或存在使得SeedStack在基于persistence.xml的配置之间做出选择(但并不明显)。
此外,“无spring实体管理器”异常使我认为您已经将SeedStack配置为允许Spring管理JPA事务(使用spring.manageJpa配置属性)。如果是这样的话,这与您的SeedStack JPA设置是矛盾的。
在SeedStack/Spring批处理中,您可以选择:
spring.manageJpa设置为true。这将允许SeedStack托管代码使用Spring配置的JPA事务管理器。让Spring在Spring批处理作业期间提供更好的性能,因此我建议使用第二个选项(但只适用于批处理作业)。
https://stackoverflow.com/questions/57054893
复制相似问题