2

我是 JPA 的新手。我的代码尝试连接到 Oracle 10.3 数据库以填充一些表。但是,在它到达代码填充之前,它会在 EntityManagerFactoryImpl.createEntityManager(String) 中引发 NullPointerException。我已经验证该emf变量不为空。这是 Populator.java 中的相关代码,就像许多教程示例一样:

public static void main(String[] args) {
    EntityManagerFactory emf =
        Persistence.createEntityManagerFactory("LeaveSchedulerJPA");
    EntityManager em = emf.createEntityManager();

异常跟踪是:

[EL Severe]: 2012-10-11 14:37:02.415--ServerSession(37999235)--java.lang.NullPointerException
    at java.util.ResourceBundle.getBundle(ResourceBundle.java:950)
    at org.eclipse.persistence.exceptions.i18n.ExceptionMessageGenerator.buildMessage(ExceptionMessageGenerator.java:47)
    at org.eclipse.persistence.exceptions.ValidationException.errorDecryptingPassword(ValidationException.java:864)
    at org.eclipse.persistence.internal.security.JCEEncryptor.decryptPassword(JCEEncryptor.java:124)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.updateLogins(EntityManagerSetupImpl.java:1183)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.updateServerSession(EntityManagerSetupImpl.java:1450)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:372)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:164)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:221)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:209)
    at com.engilitycorp.leaveschedulerjpa.Populator.main(Populator.java:28)

我的 persistence.xml 在下面。当我从 Eclipse 中使用指定的 URL 来生成与表对应的类时,指定的 URL 有效。有任何想法吗?

<?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="LeaveSchedulerJPA" transaction-type="RESOURCE_LOCAL">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <class>com.engilitycorp.leaveschedulerjpa.Holiday</class>
        <class>com.engilitycorp.leaveschedulerjpa.Leave</class>
        <class>com.engilitycorp.leaveschedulerjpa.LeaveType</class>
        <class>com.engilitycorp.leaveschedulerjpa.Notification</class>
        <class>com.engilitycorp.leaveschedulerjpa.NotificationType</class>
        <class>com.engilitycorp.leaveschedulerjpa.Role</class>
        <class>com.engilitycorp.leaveschedulerjpa.User</class>
        <properties>
        <property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@localhost:1521:xe"/>
            <property name="javax.persistence.jdbc.user" value="leavescheduler"/>
            <property name="javax.persistence.jdbc.password" value="xxxx"/>
            <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver"/>
        </properties>
    </persistence-unit>
</persistence>
4

1 回答 1

0

问题是我试图测试持久性,就好像它是一个独立的 Java 应用程序一样。该文档指出 EntityManagerFactoryImpl 维护“对活动 ServerSession 的引用”。当我在 WebLogic 中运行相同的代码时,它运行良好。

一位同事能够运行与独立 Java 应用程序相同的代码。我还没有弄清楚关键的配置差异是什么。

于 2012-10-12T16:58:33.857 回答