我是 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>