EJB、JPA 和 Eclipse 的连接问题

发布于 2024-12-09 14:08:43 字数 14259 浏览 0 评论 0 原文

我出于学习目的制作了一个非常简单的员工课程。我在 Glassfish 中创建了 JDBC 资源和连接池,并将 JPA Facet 添加到我的 Eclipse 项目中。我现在只是尝试通过右键单击 Eclipse 项目并使用 JPA 工具和从实体生成表来从我的实体生成表。我还在eclipse中添加了数据库并连接到它。

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="TestAreaPU">
        <jta-data-source>jdbc/testareadb</jta-data-source>
    </persistence-unit>
</persistence>

员工实体

@Entity
public class Employee {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String firstName;
    private String lastName;

    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
}

错误

[EL Warning]: PersistenceUnitInfo testareapu has transactionType RESOURCE_LOCAL and therefore jtaDataSource will be ignored
[EL Info]: EclipseLink, version: Eclipse Persistence Services - 2.3.0.v20110604-r9504
[EL Fine]: Detected Vendor platform: org.eclipse.persistence.platform.database.JavaDBPlatform
[EL Config]: Connection(771811155)--connecting(DatabaseLogin(   platform=>JavaDBPlatform    user name=>"APP"    datasource URL=>"jdbc:derby://localhost:1527/testareadb;create=true" ))
[EL Config]: Connection(1028854205)--Connected: jdbc:derby://localhost:1527/testareadb;create=true  User: APP   Database: Apache Derby  Version: 10.6.2.1 - (999685)    Driver: Apache Derby Network Client JDBC Driver  Version: 10.8.1.2 - (1095077)
[EL Config]: Connection(414297791)--connecting(DatabaseLogin(   platform=>JavaDBPlatform    user name=> "APP"   datasource URL=>"jdbc:derby://localhost:1527/testareadb;create=true" ))
[EL Config]: Connection(960989763)--Connected: jdbc:derby://localhost:1527/testareadb;create=true   User: APP   Database: Apache Derby  Version: 10.6.2.1 - (999685)    Driver: Apache Derby Network Client JDBC Driver  Version: 10.8.1.2 - (1095077)
[EL Info]: file:/C:/Users/Andreas/TestAreaEJB/build/classes/_testareapu_url=jdbc:derby://localhost:1527/testareadb;create=true_user=APP login successful
[EL Warning]: The collection of metamodel types is empty. Model classes may not have been found during entity search for Java SE and some Java EE container managed persistence units.  Please verify that your entity classes are referenced in persistence.xml using either <class> elements or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element
[EL Config]: Connection(1028854205)--disconnect
[EL Info]: file:/C:/Users/Andreas/TestAreaEJB/build/classes/_testareapu_url=jdbc:derby://localhost:1527/testareadb;create=true_user=APP logout successful
[EL Config]: Connection(771811155)--disconnect
[EL Config]: Connection(960989763)--disconnect

新错误:

[EL Severe]: Local Exception Stack: 
Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [jdbc/testareadb].
Internal Exception: javax.naming.NamingException: Lookup failed for 'jdbc/testareadb' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is java.lang.RuntimeException: Orb initialization erorr]]
    at org.eclipse.persistence.exceptions.ValidationException.cannotAcquireDataSource(ValidationException.java:485)
    at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:109)
    at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:582)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:206)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:472)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getDatabaseSession(EntityManagerFactoryDelegate.java:188)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:277)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:290)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:268)
    at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.perform(Main.java:86)
    at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.execute(Main.java:77)
    at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.main(Main.java:64)
Caused by: javax.naming.NamingException: Lookup failed for 'jdbc/testareadb' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is java.lang.RuntimeException: Orb initialization erorr]]
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:654)
    at javax.naming.InitialContext.lookup(InitialContext.java:396)
    at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:103)
    ... 11 more
Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is java.lang.RuntimeException: Orb initialization erorr]
    at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:352)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:504)
    ... 15 more
Caused by: java.lang.RuntimeException: Orb initialization erorr
    at org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:180)
    at com.sun.enterprise.naming.impl.SerialContext.getORB(SerialContext.java:365)
    at com.sun.enterprise.naming.impl.SerialContext.getProviderCacheKey(SerialContext.java:372)
    at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:402)
    at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:347)
    ... 16 more
Caused by: java.lang.NullPointerException
    at org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:152)
    ... 20 more

Exception in thread "main" javax.persistence.PersistenceException: Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [jdbc/testareadb].
Internal Exception: javax.naming.NamingException: Lookup failed for 'jdbc/testareadb' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is java.lang.RuntimeException: Orb initialization erorr]]
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:501)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getDatabaseSession(EntityManagerFactoryDelegate.java:188)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:277)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:290)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:268)
    at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.perform(Main.java:86)
    at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.execute(Main.java:77)
    at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.main(Main.java:64)
Caused by: Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [jdbc/testareadb].
Internal Exception: javax.naming.NamingException: Lookup failed for 'jdbc/testareadb' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is java.lang.RuntimeException: Orb initialization erorr]]
    at org.eclipse.persistence.exceptions.ValidationException.cannotAcquireDataSource(ValidationException.java:485)
    at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:109)
    at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:582)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:206)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:472)
    ... 7 more
Caused by: javax.naming.NamingException: Lookup failed for 'jdbc/testareadb' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is java.lang.RuntimeException: Orb initialization erorr]]
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:654)
    at javax.naming.InitialContext.lookup(InitialContext.java:396)
    at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:103)
    ... 11 more
Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is java.lang.RuntimeException: Orb initialization erorr]
    at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:352)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:504)
    ... 15 more
Caused by: java.lang.RuntimeException: Orb initialization erorr
    at org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:180)
    at com.sun.enterprise.naming.impl.SerialContext.getORB(SerialContext.java:365)
    at com.sun.enterprise.naming.impl.SerialContext.getProviderCacheKey(SerialContext.java:372)
    at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:402)
    at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:347)
    ... 16 more
Caused by: java.lang.NullPointerException
    at org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:152)
    ... 20 more

I have made a really simple Employee class just for learning purposes. I have made a JDBC resource and connection pool in Glassfish and added the JPA Facet to my Eclipse project. I am now just trying to generate the table from my Entity by rightcliking the Eclipse project and using JPA Tools and Generate tables from entities. And I have also added the database in eclipse and I am connected to it.

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="TestAreaPU">
        <jta-data-source>jdbc/testareadb</jta-data-source>
    </persistence-unit>
</persistence>

Employee Entity

@Entity
public class Employee {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String firstName;
    private String lastName;

    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
}

Error

[EL Warning]: PersistenceUnitInfo testareapu has transactionType RESOURCE_LOCAL and therefore jtaDataSource will be ignored
[EL Info]: EclipseLink, version: Eclipse Persistence Services - 2.3.0.v20110604-r9504
[EL Fine]: Detected Vendor platform: org.eclipse.persistence.platform.database.JavaDBPlatform
[EL Config]: Connection(771811155)--connecting(DatabaseLogin(   platform=>JavaDBPlatform    user name=>"APP"    datasource URL=>"jdbc:derby://localhost:1527/testareadb;create=true" ))
[EL Config]: Connection(1028854205)--Connected: jdbc:derby://localhost:1527/testareadb;create=true  User: APP   Database: Apache Derby  Version: 10.6.2.1 - (999685)    Driver: Apache Derby Network Client JDBC Driver  Version: 10.8.1.2 - (1095077)
[EL Config]: Connection(414297791)--connecting(DatabaseLogin(   platform=>JavaDBPlatform    user name=> "APP"   datasource URL=>"jdbc:derby://localhost:1527/testareadb;create=true" ))
[EL Config]: Connection(960989763)--Connected: jdbc:derby://localhost:1527/testareadb;create=true   User: APP   Database: Apache Derby  Version: 10.6.2.1 - (999685)    Driver: Apache Derby Network Client JDBC Driver  Version: 10.8.1.2 - (1095077)
[EL Info]: file:/C:/Users/Andreas/TestAreaEJB/build/classes/_testareapu_url=jdbc:derby://localhost:1527/testareadb;create=true_user=APP login successful
[EL Warning]: The collection of metamodel types is empty. Model classes may not have been found during entity search for Java SE and some Java EE container managed persistence units.  Please verify that your entity classes are referenced in persistence.xml using either <class> elements or a global <exclude-unlisted-classes>false</exclude-unlisted-classes> element
[EL Config]: Connection(1028854205)--disconnect
[EL Info]: file:/C:/Users/Andreas/TestAreaEJB/build/classes/_testareapu_url=jdbc:derby://localhost:1527/testareadb;create=true_user=APP logout successful
[EL Config]: Connection(771811155)--disconnect
[EL Config]: Connection(960989763)--disconnect

New error:

[EL Severe]: Local Exception Stack: 
Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [jdbc/testareadb].
Internal Exception: javax.naming.NamingException: Lookup failed for 'jdbc/testareadb' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is java.lang.RuntimeException: Orb initialization erorr]]
    at org.eclipse.persistence.exceptions.ValidationException.cannotAcquireDataSource(ValidationException.java:485)
    at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:109)
    at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:582)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:206)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:472)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getDatabaseSession(EntityManagerFactoryDelegate.java:188)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:277)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:290)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:268)
    at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.perform(Main.java:86)
    at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.execute(Main.java:77)
    at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.main(Main.java:64)
Caused by: javax.naming.NamingException: Lookup failed for 'jdbc/testareadb' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is java.lang.RuntimeException: Orb initialization erorr]]
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:654)
    at javax.naming.InitialContext.lookup(InitialContext.java:396)
    at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:103)
    ... 11 more
Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is java.lang.RuntimeException: Orb initialization erorr]
    at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:352)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:504)
    ... 15 more
Caused by: java.lang.RuntimeException: Orb initialization erorr
    at org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:180)
    at com.sun.enterprise.naming.impl.SerialContext.getORB(SerialContext.java:365)
    at com.sun.enterprise.naming.impl.SerialContext.getProviderCacheKey(SerialContext.java:372)
    at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:402)
    at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:347)
    ... 16 more
Caused by: java.lang.NullPointerException
    at org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:152)
    ... 20 more

Exception in thread "main" javax.persistence.PersistenceException: Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [jdbc/testareadb].
Internal Exception: javax.naming.NamingException: Lookup failed for 'jdbc/testareadb' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is java.lang.RuntimeException: Orb initialization erorr]]
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:501)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getDatabaseSession(EntityManagerFactoryDelegate.java:188)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:277)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:290)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:268)
    at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.perform(Main.java:86)
    at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.execute(Main.java:77)
    at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.main(Main.java:64)
Caused by: Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [jdbc/testareadb].
Internal Exception: javax.naming.NamingException: Lookup failed for 'jdbc/testareadb' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is java.lang.RuntimeException: Orb initialization erorr]]
    at org.eclipse.persistence.exceptions.ValidationException.cannotAcquireDataSource(ValidationException.java:485)
    at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:109)
    at org.eclipse.persistence.sessions.DatasourceLogin.connectToDatasource(DatasourceLogin.java:162)
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:582)
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:206)
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:472)
    ... 7 more
Caused by: javax.naming.NamingException: Lookup failed for 'jdbc/testareadb' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is java.lang.RuntimeException: Orb initialization erorr]]
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:654)
    at javax.naming.InitialContext.lookup(InitialContext.java:396)
    at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:103)
    ... 11 more
Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is java.lang.RuntimeException: Orb initialization erorr]
    at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:352)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:504)
    ... 15 more
Caused by: java.lang.RuntimeException: Orb initialization erorr
    at org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:180)
    at com.sun.enterprise.naming.impl.SerialContext.getORB(SerialContext.java:365)
    at com.sun.enterprise.naming.impl.SerialContext.getProviderCacheKey(SerialContext.java:372)
    at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:402)
    at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:347)
    ... 16 more
Caused by: java.lang.NullPointerException
    at org.glassfish.enterprise.iiop.api.GlassFishORBHelper.getORB(GlassFishORBHelper.java:152)
    ... 20 more

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

够运 2024-12-16 14:08:43

我认为 JTA 仅在 GlassFish 等容器中受支持,而不是在 Eclipse 中受支持。

添加事务类型 =“RESOURCE_LOCAL”的持久性单元并从 Eclipse 调用它来创建数据库

,或者

将“;create=true”(对于 Apache Derby)添加到 GlassFish 配置中的连接 URL 并部署应用程序。

您可能还想将 eclipselink.ddl- Generation 属性设置为“create-tables”或“drop-and-create-tables”

http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_%28ELUG%29#Using_EclipseLink_JPA_Extensions_for_Schema_Generation

I think JTA is only supported in a container such as GlassFish and not from Eclipse.

Either add a persistence unit with transaction-type = "RESOURCE_LOCAL" and call this from Eclipse to create the db

or

add ";create=true" (for Apache Derby) to the connection URL in the GlassFish configuration and deploy your application.

You might also want to set the eclipselink.ddl-generation property to "create-tables" or "drop-and-create-tables"

http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_%28ELUG%29#Using_EclipseLink_JPA_Extensions_for_Schema_Generation

冷夜 2024-12-16 14:08:43

问题似乎出在您的 persistence.xml 中,当您定义 JTA 数据源 "jdbc/testareadb" 时,您实际上应该引用连接池 > 而不是 JDBC 资源

例如,我的 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="MyAppPU" transaction-type="JTA">
        <jta-data-source>MyAppPool</jta-data-source>
    </persistence-unit>
</persistence>

然后我需要在 Glassfish 创建一个名为 "jdbc/MyAppDS" 的 JDBC 资源和一个名为 的连接池“MyAppPool” 将由我的 persistence.xml 引用。知道了?

如果您不知道如何在 Glassfish Console 上执行此操作,请查看这篇文章:
http://gardiary. wordpress.com/2009/07/30/create-jdbc-connection-pool-and-resource-in-glassfish/

The problem seems to be in your persistence.xml, when you define the JTA data source "jdbc/testareadb" you should actually reference the Connection Pool and not the JDBC Resource.

For example, my persistence.xml is something like this:

<?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="MyAppPU" transaction-type="JTA">
        <jta-data-source>MyAppPool</jta-data-source>
    </persistence-unit>
</persistence>

Then I need to create a JDBC Resource named "jdbc/MyAppDS" at Glassfish and a Connection Pool named "MyAppPool" that is going to be referenced by my persistence.xml. Got it?

If you don't know how to do it on Glassfish Console, take a look at this article:
http://gardiary.wordpress.com/2009/07/30/create-jdbc-connection-pool-and-resource-in-glassfish/

自找没趣 2024-12-16 14:08:43

首先,如果我做实体,我想指定表和列名称:

@Entity
@Table (name = "Employee")
public class Employee {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Column (name = "firstName") //name is optional, default this is fieldName
    private String firstName;
    @Column (name = "lastName")
    private String lastName;

    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
}

如果您使用 jdbc/testareadb,则意味着您应该在服务器上配置资源,抛出 glasfish 管理控制台,其中 jdbc/testareadb 是资源的 JNDI 名称。
如果您只是初学者,我不建议您一开始就这样做。

根据 JPA 2.0 规范,参数 transaction-type 是可选的,瘦客户端默认为 resource-local,容器事务默认为 JTA

最好将属性添加到 persistence.xml,而不是 jta-data-source
例子如上:

<persistence-unit name="Unit-name" >
<class>com.yourCompany.db.Employee</class>
<properties>
      <property name="eclipselink.target-database" value="DERBY"/>
      <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
      <property name="eclipselink.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
      <property name="eclipselink.jdbc.url" value="jdbc:derby://localhost:1527/chapter02DB;create=true"/>
      <property name="eclipselink.jdbc.user" value="userName"/>
      <property name="eclipselink.jdbc.password" value="userPassword"/>
    </properties>
</persistence-unit>

祝你好运!

At first, If I do entity, I would like specify table and column names:

@Entity
@Table (name = "Employee")
public class Employee {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Column (name = "firstName") //name is optional, default this is fieldName
    private String firstName;
    @Column (name = "lastName")
    private String lastName;

    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
}

If you use <jta-data-source>jdbc/testareadb</jta-data-source>, it mean you should configure resource on server, throw glasfish admin console, where jdbc/testareadb is JNDI name of resource.
If you only beginner at this, I don`t recommend do, it at first.

According to JPA 2.0 spec parameter transaction-type is optional and default is resource-local at thin client and JTA at container transactions.

Instead of jta-data-source better add properties to persistence.xml
Exapmle is above:

<persistence-unit name="Unit-name" >
<class>com.yourCompany.db.Employee</class>
<properties>
      <property name="eclipselink.target-database" value="DERBY"/>
      <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
      <property name="eclipselink.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
      <property name="eclipselink.jdbc.url" value="jdbc:derby://localhost:1527/chapter02DB;create=true"/>
      <property name="eclipselink.jdbc.user" value="userName"/>
      <property name="eclipselink.jdbc.password" value="userPassword"/>
    </properties>
</persistence-unit>

Good luck!

反差帅 2024-12-16 14:08:43

您可能需要为您的环境定义数据源文件

You might need to define a data source file for your environment

脱离于你 2024-12-16 14:08:43

你肯定在 persistence.xml 中错过了你的持久性类的列表(尽管这不是 javax.naming.NamingException 的原因) - 我是不熟悉 EclipseLink,但这表明了这一点:

[EL Warning]: The collection of metamodel types is empty. (...)

将类名添加到 persistence.xml 中:

<?xml version="1.0" encoding="UTF-8"?>
<persistence (...)>
    <persistence-unit name="TestAreaPU">
        <jta-data-source>jdbc/testareadb</jta-data-source>
        <class>fully-qualified-name-of-Employee</class>
    </persistence-unit>
</persistence>

What you surely miss in persistence.xml (though it's not the reason for the javax.naming.NamingException) is the list of your persistence class(es) — I'm not familiar with EclipseLink, but this suggests it:

[EL Warning]: The collection of metamodel types is empty. (...)

Add the class name to your persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence (...)>
    <persistence-unit name="TestAreaPU">
        <jta-data-source>jdbc/testareadb</jta-data-source>
        <class>fully-qualified-name-of-Employee</class>
    </persistence-unit>
</persistence>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文