簡體   English   中英

使用JPA附加組件找不到SeedStack“ persistence.xml”

[英]SeedStack “persistence.xml” not found using JPA add-on

我正在設置一個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

我想將JPA與SeedStack一起正確使用,而不必執行persistence.xml。

此處查看示例,您的SeedStack JPA配置缺少對數據源的引用:

    jpa:
     units:
       myUnit:
         datasource: myDatasource
         properties:
           hibernate.dialect: org.hibernate.dialect.PostgreSQLDialect
           hibernate.hbm2ddl.auto: update

缺少datasource屬性是使SeedStack在是否基於persistence.xml的配置之間進行選擇的原因(但這並不明顯)。

另外,“ No springEntitymanager”異常使我認為您已經配置了SeedStack以讓Spring管理JPA事務(使用spring.manageJpa config屬性)。 如果真是這樣,那就與您的SeedStack JPA設置相矛盾。

在SeedStack / Spring批處理中,您可以選擇:

  • 讓SeedStack管理JPA。 在這種情況下,您可以使用SeedStack配置JPA,並僅在SeedStack托管的代碼(業務服務,存儲庫等)中使用JPA(包括@Transactional批注)。
  • 讓Spring管理JPA。 在這種情況下,您可以使用Spring配置JPA(不使用任何SeedStack配置),並將spring.manageJpa設置為true。 這將允許SeedStack管理的代碼使用Spring配置的JPA事務管理器。

讓Spring管理JPA可以在Spring批處理作業中提供更好的性能,因此我建議使用第二種選擇(但僅適用於批處理作業)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM