【问题标题】:Configuration of persistence.xml while using websphere 8.5.5.1使用 websphere 8.5.5.1 时配置 persistence.xml
【发布时间】:2023-03-03 03:46:01
【问题描述】:

我正在编写一个使用 Servlet 3.0、Jsp 和 JPA 2.0 的应用程序,并将其部署到 Websphere 应用程序服务器 8.5 中。 由于我已经配置到 ibm websphere 控制台、数据源和 jdbc 驱动程序以及 j2c 身份验证(我使用 oracle 11g 作为数据库)。如果我需要指定 openJPA jar 并将其添加到我的项目中,我不知道我的 persistence.xml 应该是什么样子。 现在我放入persistence.xml的任何东西都有这个问题:

Error 500: <openjpa-2.2.3-SNAPSHOT-r422266:1764177 fatal user error> org.apache.openjpa.persistence.ArgumentException

我该怎么办?也许我错过了 JPA 的工作原理

提前致谢

【问题讨论】:

    标签: java jpa websphere openjpa persistence.xml


    【解决方案1】:

    OpenJPA jar 应该由 WebSphere 提供并且可用于您的应用程序。这里有一个 JPA 示例:https://developer.ibm.com/wasdev/downloads/#asset/samples-Java_Persistence_API_JPA_Sample

    在示例中,您可以看到 persistence.xml 文件的示例:

    <?xml version="1.0" encoding="UTF-8"?>
    <persistence version="2.0"
                 xmlns="http://java.sun.com/xml/ns/persistence"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    
      <persistence-unit name="jpasamplepersistenceunit">
    
        <jta-data-source>java:comp/env/jdbc/samplejpadatasource</jta-data-source>
        <non-jta-data-source>java:comp/env/jdbc/samplejpadatasourcenonjta</non-jta-data-source>
    
        <class>wasdev.sample.jpa.Thing</class>
        <exclude-unlisted-classes>true</exclude-unlisted-classes>
        <properties>
          <!-- These properties are creating the database on the fly. We are using them to avoid users having
              to create a database to run the sample. 
              See also the create=true line in the datasource meta data. -->
          <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)" />
          <property name="openjpa.jdbc.DBDictionary" value="derby" />
    
          <!-- EclipseLink specific properties to create the database. They are only used if using the jpa-2.1 feature. -->
            <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
            <property name="eclipselink.ddl-generation.output-mode" value="both" />
    
        </properties>
      </persistence-unit>
    
    </persistence>
    

    我认为您的错误不是由 OpenJPA jar 不可用引起的。这可能是因为您的数据库配置不正确。确保您的 persistence.xml 文件正确引用了您的数据源。

    【讨论】:

      猜你喜欢
      • 2014-05-16
      • 2011-04-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多