【问题标题】:Generating metamodel classes with JPA 2.1使用 JPA 2.1 生成元模型类
【发布时间】:2013-07-20 16:05:54
【问题描述】:

我在使用休眠元模型生成器时遇到问题:

java: Error unmarshalling /META-INF/persistence.xml with exception :
   javax.xml.bind.UnmarshalException
   - with linked exception:
  [org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 103; cvc-elt.1: Cannot find the declaration of element 'persistence'.]

这是我的 persistence.xml:

<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
                 http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/persistence/persistence_2_1.xsd">

  <persistence-unit name="wespital" transaction-type="JTA">
    <jta-data-source>jdbc/wespital</jta-data-source>
  </persistence-unit>
</persistence>

当前版本(1.2.Final)似乎不支持 JPA 2.1,我在 git 存储库中没有找到该生成器的任何 beta 版本。还有哪些其他选项可以生成元模型类?我使用wildfly作为应用服务器。

【问题讨论】:

    标签: java jpa jpa-2.1


    【解决方案1】:

    2013 年 8 月 9 日发布了一个新版本 (1.3.0.Final),应该可以解决您的问题。

    【讨论】:

      【解决方案2】:

      DataNucleus JPA 元模型生成器生成适用于 JPA 2.0/2.1 的类,请参阅 DataNucleus docs

      【讨论】:

        【解决方案3】:

        我使用了 eclipselink 项目中的元模型生成器,它似乎工作正常。

        <dependency>
          <groupId>org.eclipse.persistence</groupId>
          <artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
          <version>2.5.0</version>
          <scope>provided</scope>
        </dependency>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-11-27
          • 2011-03-03
          • 1970-01-01
          • 1970-01-01
          • 2021-12-22
          • 2020-03-06
          相关资源
          最近更新 更多