Generate Tables from Entities results in NoInitialContextException - eclipse

When I try to generate Database Tables from my project's Entities the Exception below is thrown.
If I understand correctly, the Exception suggested to specify java.naming.factory.initial:
So I went through several parts of JBoss-Documentation, not quite sure what I was looking for, did experiments with a jndi.properties-file and realized in the end that I am absolutely clueless.
BTW: The generation of Entities from Tables (so the other way round) works without problems.
[EL Info]: EclipseLink, version: Eclipse Persistence Services - 2.3.2.v20111125-r10461
[EL Severe]: Local Exception Stack:
Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [java:jboss/datasources/MySQLDS].
Internal Exception: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at org.eclipse.persistence.exceptions.ValidationException.cannotAcquireDataSource(ValidationException.java:497)
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:584)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:206)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:488)
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:294)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:272)
at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.perform(Main.java:85)
at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.execute(Main.java:76)
at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.main(Main.java:63)
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.lookup(Unknown Source)
at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:103)
... 11 more
Exception in thread "main" javax.persistence.PersistenceException: Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [java:jboss/datasources/MySQLDS].
Internal Exception: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:517)
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:294)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:272)
at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.perform(Main.java:85)
at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.execute(Main.java:76)
at org.eclipse.jpt.jpa.eclipselink.core.ddlgen.Main.main(Main.java:63)
Caused by: Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [java:jboss/datasources/MySQLDS].
Internal Exception: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at org.eclipse.persistence.exceptions.ValidationException.cannotAcquireDataSource(ValidationException.java:497)
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:584)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:206)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:488)
... 7 more
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.lookup(Unknown Source)
at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:103)
... 11 more
my 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="DynamicWebProject" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>java:jboss/datasources/MySQLDS</jta-data-source>
<class>hoho.model.generated.AvailabilityDeliveryMethod</class>
<class>hoho.model.generated.AvailabilityItem</class>
<class>hoho.model.generated.AvailabilityRestaurant</class>
<class>hoho.model.generated.Category</class>
<class>hoho.model.generated.ContactData</class>
<class>hoho.model.generated.Deliverer</class>
<class>hoho.model.generated.DeliveryMethod</class>
<class>hoho.model.generated.DeliveryMethodHasPrice</class>
<class>hoho.model.generated.Item</class>
<class>hoho.model.generated.Label</class>
<class>hoho.model.generated.OrderHasItem</class>
<class>hoho.model.generated.OrderLimitation</class>
<class>hoho.model.generated.PaymentMethod</class>
<class>hoho.model.generated.Person</class>
<class>hoho.model.generated.PersonPreference</class>
<class>hoho.model.generated.Price</class>
<class>hoho.model.generated.PurchaseOrder</class>
<class>hoho.model.generated.Restaurant</class>
<class>hoho.model.generated.Tag</class>
<class>hoho.model.generated.Image</class>
<class>hoho.model.generated.MimeType</class>
<class>hoho.model.generated.TaxRate</class>
<properties>
<!-- <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/> -->
<property name="javax.persistence.jtaDataSource" value="java:jboss/datasources/MySQLDS" />
</properties>
</persistence-unit>
</persistence>

The JPA-Tools are not working with resource type JTA. Change it temporary to RESOURCE_LOCAL.
See also Generating tables from entities

Related

Classes inside persistence.xml will be ignored

I have here a wildfly 24.0.1 (on OpenJDK 11) and a ear with following structure:
MyPrj.ear
|- MyPrj_EJB.jar
`- MyPrj_Web.war
My persistence.xml is placed in MyPrj.ear/MyPrj_EJB.jar/META-INF/persistence.xml. I'm sure the persistence.xml isn't anywhere else.
The persistence.xml has following contents:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="myPrj">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>java:/myPrj</jta-data-source>
<class>my.prj.cfg.Config</class>
<properties>
<property name="eclipselink.query-results-cache" value="true"/>
<property name="eclipselink.cache.shared.default" value="true"/>
<property name="eclipselink.target-server" value="JBoss"/>
<property name="eclipselink.weaving" value="false"/>
<property name="jboss.as.jpa.providerModule" value="org.eclipse.persistence"/>
<!-- property name="eclipselink.logging.level" value="FINE" / -->
</properties>
</persistence-unit>
</persistence>
I'm sure that the persistence.xml can be readed, because if I put an invalid character into the persistence-unit name (like an "/": <persistence-unit name="/myPrj">) I get the following error while deploying the application:
Caused by: java.lang.IllegalArgumentException: WFLYJPA0043: Persistence unit name (/myPrj) contains illegal '/' character
So I'm assuming that my persistence.xml is put in the right place and can be read successfully.
But its seems that my <class>-definition will be ignored. Every time if I deploy the ear, I get in the wildfly log file:
...
2022-07-04 18:51:15,694 INFO [org.jboss.as.jpa] (MSC service thread 1-4) WFLYJPA0002: Read persistence.xml for myPrj
2022-07-04 18:52:48,400 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 141) WFLYJPA0003: Starting Persistence Unit Service 'MyPrj.ear/MyPrj_EJB.jar#myPrj'
...
2022-07-04 18:53:16,182 WARN [org.eclipse.persistence] (ServerService Thread Pool -- 184) session_manager_no_partition
...
If I start the application (open the web site) I get:
...
2022-07-04 18:57:45,366 INFO [org.eclipse.persistence] (default task-1) EclipseLink, version: Eclipse Persistence Services - 2.6.0.v20150309-bf26070
2022-07-04 18:57:45,444 INFO [org.eclipse.persistence.connection] (default task-1)
connecting(DatabaseLogin(
platform=>PostgreSQLPlatform
user name=> ""
connector=>JNDIConnector datasource name=>null
))
2022-07-04 18:57:45,444 INFO [org.eclipse.persistence.connection] (default task-1)
Connected: jdbc:postgresql://localhost:5432/myDB
User: myUser
Database: PostgreSQL Version: 9.2.24
Driver: PostgreSQL JDBC Driver Version: 42.2.23
2022-07-04 18:57:45,444 INFO [org.eclipse.persistence.connection] (default task-1)
connecting(DatabaseLogin(
platform=>PostgreSQLPlatform
user name=> ""
connector=>JNDIConnector datasource name=>null
))
2022-07-04 18:57:45,444 INFO [org.eclipse.persistence.connection] (default task-1)
Connected: jdbc:postgresql://localhost:5432/myDB
User: myUser
Database: PostgreSQL Version: 9.2.24
Driver: PostgreSQL JDBC Driver Version: 42.2.23
2022-07-04 18:57:45,446 INFO [org.eclipse.persistence.connection] (default task-1)
/vfs:/content/MyPrj.ear/MyPrj_EJB.jar/_myPrj login successful
2022-07-04 18:57:45,509 WARN [org.eclipse.persistence.metamodel] (default task-1) 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
2022-07-04 18:57:45,606 ERROR [org.jboss.as.ejb3.invocation] (default task-1)
WFLYEJB0034: Jakarta Enterprise Beans Invocation failed on component ConfigDAO for
method public my.prj.cfg.Config
my.prj.cfg.ConfigDAO.loadByKey(java.lang.String):
javax.ejb.EJBTransactionRolledbackException: An exception occurred while creating
a query in EntityManager:
Exception Description: Problem compiling [SELECT obj FROM Config obj WHERE
obj.key=:parKey].
[16, 22] The abstract schema type 'Config' is unknown.
[33, 40] The state field path 'obj.key' cannot be resolved to a valid type.
at org.jboss.as.ejb3#24.0.1.Final//org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInCallerTx(CMTTxInterceptor.java:219)
Take also note of the warning 2022-07-04 18:57:45,509 WARN org.eclipse.persistence.metamodel] (default task-1) 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.
Also to use <exclude-unlisted-classes>false</exclude-unlisted-classes> instead of the <class>-definition makes no difference.
Here the #Resource annotation of the EntityManager:
#PersistenceContext(unitName="myPrj")
private EntityManager em = null;
And the annotation of the Config entity:
#Entity(name="Config")
#Table(name = "Cfg")
public class Config implements Serializable {
...
#Column(name="key")
private String key = null;
...
}
On the same wildfly I have another EAR running (in a separate standalone instance) which also have JPA access to a database (also eclipselink via persistence.xml) which works without any problems.
What can be wrong here?
Found it! After upgrading eclipselink to V2.7.10 (store eclipselink.jar into .../wildfly-24.0.1.Final/modules/system/layers/base/org/eclipse/persistence/main/) I can deploy and start the application. Not sure which version of eclipselink was used before that (the jar file name don't contains the version information ...)
Switching to eclipselink 3.0.2 don't works because of this problem: Wildfly 21 with eclipselink 3.0 getting error as Persistence Provider not found

EclipseLink don't load properties from DataSource in Websphere Liberty Profile

I have problem with configuring JPA in Websphere Liberty Profile. EclipseLink which is default provider in WAS with feature jpa-2.1 don't read the properties from created in server.xml DataSource. I've tried to get connection from this data source without JPA and this connection was succesfull, i had access to database. But when i use JPA and then create EntityManagerFactory from my PerstistenceUnit i get exception which in my opinion means that i didn't give required parameters such as url, username and password. I tested that WAS recognize EclipseLink provider, but now i don't know what can I do with this problem. Google haven't helped me.
Persistence.xml
<persistence version="1.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_1_0.xsd">
<persistence-unit name="test-unit" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>java:comp/env/jdbc/PostgreDS</jta-data-source>
<properties>
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.ddl-generation.output-mode"
value="database" />
</properties>
</persistence-unit>
server.xml(only part with my setting of JDBC and DS)
<jdbcDriver id="myJDBCDriver" libraryRef="JDBCLib" javax.sql.XADataSource="org.postgresql.xa.PGXADataSource" >
</jdbcDriver>
<library id="JDBCLib" name="PostgreLib">
<file name="/home/hubert/JavaLibs/postgresql-9.4-1206-jdbc41.jar" id="JDBC_JAR"></file>
</library>
<dataSource id="PostrgreConnection" jdbcDriverRef="myJDBCDriver" jndiName="jdbc/PostgreDS" type="javax.sql.XADataSource">
<properties URL="jdbc:postgresql://localhost/GotSpotDB" databaseName="GotSpotDB" password="testtest" portNumber="5432" serverName="localhost" user="GotSpotAdmin"/>
</dataSource>
Logs
[ERROR ] CWWJP9992E: Exception [EclipseLink-4021] (Eclipse Persistence Services - 2.6.1.WAS-v20160106-a06c2b3): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Unable to acquire a connection from driver [null], user [null] and URL [null]. Verify that you have set the expected driver class and URL. Check your login, persistence.xml or sessions.xml resource. The jdbc.driver property should be set to a class that is compatible with your database platform
[ERROR ] SRVE0777E: Exception thrown by application class 'org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy:837'
javax.persistence.PersistenceException: Exception [EclipseLink-4021] (Eclipse Persistence Services - 2.6.1.WAS-v20160106-a06c2b3): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Unable to acquire a connection from driver [null], user [null] and URL [null]. Verify that you have set the expected driver class and URL. Check your login, persistence.xml or sessions.xml resource. The jdbc.driver property should be set to a class that is compatible with your database platform
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:837)
at [internal classes]
at pl.almost.done.TestServlet.doGet(TestServlet.java:52)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
at [internal classes]
Caused by: Exception [EclipseLink-4021] (Eclipse Persistence Services - 2.6.1.WAS-v20160106-a06c2b3): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Unable to acquire a connection from driver [null], user [null] and URL [null]. Verify that you have set the expected driver class and URL. Check your login, persistence.xml or sessions.xml resource. The jdbc.driver property should be set to a class that is compatible with your database platform
at org.eclipse.persistence.exceptions.DatabaseException.unableToAcquireConnectionFromDriverException(DatabaseException.java:383)
... 4 more

Java Persistence API Factory method error

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named Employee
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at Emp.Employee_Details.main(Employee_Details.java:74)
It seems like you forgot add persistence provider in persistence.xml. If you use hibernate, it must be something like this:
<provider>org.hibernate.ejb.HibernatePersistence</provider>

Can Web sphere Liberty manage multiple JTA sources?

when I add more that one jta-data-source in persistence.xml i run into a runtime exception
[ERROR ] CWWJP0012E: The persistence unit name is not specified and a unique persistence unit is not found in the CoplinkRestService application and CoplinkRestService.war module.
[ERROR ] CWWJP0029E: The server cannot find the persistence unit in the CoplinkRestService.war module and the CoplinkRestService application.
[ERROR ] CWNEN0035E: The java:comp/env/CLDB reference of type javax.persistence.EntityManager for the null component in the CoplinkRestService.war module of the CoplinkRestService application cannot be resolved.
[ERROR ] CNTR0019E: EJB threw an unexpected (non-declared) exception during invocation of method "getPersonDetails". Exception data: javax.ejb.EJBException: The java:comp/env/CLDB reference of type javax.persistence.EntityManager for the null component in the CoplinkRestService.war module of the CoplinkRestService application cannot be resolved.
at com.ibm.wsspi.injectionengine.InjectionBinding.getInjectionObject(InjectionBinding.java:1494)
at [internal classes]
at com.ibm.coplink.enterprise.details.person.EJSLocalNSLPersonDetailsEJB_df3bc29f.getPersonDetails(EJSLocalNSLPersonDetailsEJB_df3bc29f.java)
at com.ibm.coplink.enterprise.details.DetailsHandlerEJB$$Lambda$8.000000001A297440.apply(Unknown Source)
at com.ibm.coplink.enterprise.details.DetailsHandlerEJB.getDetails(DetailsHandlerEJB.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:495)
at com.ibm.ejs.container.EJSContainer.invokeProceed(EJSContainer.java:5323)
at [internal classes]
at com.ibm.coplink.enterprise.details.EJSLocalNSLDetailsHandlerEJB_c56b7144.getDetails(EJSLocalNSLDetailsHandlerEJB_c56b7144.java)
at com.ibm.coplink.service.CoplinkRestServiceImpl.deleteMe(CoplinkRestServiceImpl.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:495)
at com.ibm.ws.jaxrs20.server.LibertyJaxRsServerFactoryBean.performInvocation(LibertyJaxRsServerFactoryBean.java:607)
at [internal classes]
[ERROR ] CNTR0020E: EJB threw an unexpected (non-declared) exception during invocation of method "getDetails" on bean "BeanId(CoplinkRestService#CoplinkRestService.war#DetailsHandlerEJB, null)". Exception data: javax.ejb.EJBTransactionRolledbackException: nested exception is: javax.ejb.EJBException: The java:comp/env/CLDB reference of type javax.persistence.EntityManager for the null component in the CoplinkRestService.war module of the CoplinkRestService application cannot be resolved.
at com.ibm.ejs.container.BusinessExceptionMappingStrategy.mapCSIException(BusinessExceptionMappingStrategy.java:127)
at [internal classes]
at com.ibm.coplink.enterprise.details.person.EJSLocalNSLPersonDetailsEJB_df3bc29f.getPersonDetails(EJSLocalNSLPersonDetailsEJB_df3bc29f.java)
at com.ibm.coplink.enterprise.details.DetailsHandlerEJB$$Lambda$8.000000001A297440.apply(Unknown Source)
at com.ibm.coplink.enterprise.details.DetailsHandlerEJB.getDetails(DetailsHandlerEJB.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:495)
at com.ibm.ejs.container.EJSContainer.invokeProceed(EJSContainer.java:5323)
at [internal classes]
at com.ibm.coplink.enterprise.details.EJSLocalNSLDetailsHandlerEJB_c56b7144.getDetails(EJSLocalNSLDetailsHandlerEJB_c56b7144.java)
at com.ibm.coplink.service.CoplinkRestServiceImpl.deleteMe(CoplinkRestServiceImpl.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:495)
at com.ibm.ws.jaxrs20.server.LibertyJaxRsServerFactoryBean.performInvocation(LibertyJaxRsServerFactoryBean.java:607)
at [internal classes]
Caused by: javax.ejb.EJBException: The java:comp/env/CLDB reference of type javax.persistence.EntityManager for the null component in the CoplinkRestService.war module of the CoplinkRestService application cannot be resolved.
at com.ibm.wsspi.injectionengine.InjectionBinding.getInjectionObject(InjectionBinding.java:1494)
... 18 more
[WARNING ] Application {http://service.coplink.ibm.com/}CoplinkRestServiceImpl has thrown exception, unwinding now
nested exception is: javax.ejb.EJBException: The java:comp/env/CLDB reference of type javax.persistence.EntityManager for the null component in the CoplinkRestService.war module of the CoplinkRestService application cannot be resolved.
[WARNING ] Exception in handleFault on interceptor org.apache.cxf.jaxrs.interceptor.JAXRSDefaultFaultOutInterceptor#8ca66b2
nested exception is: javax.ejb.EJBException: The java:comp/env/CLDB reference of type javax.persistence.EntityManager for the null component in the CoplinkRestService.war module of the CoplinkRestService application cannot be resolved.
[ERROR ] Error occurred during error handling, give up!
nested exception is: javax.ejb.EJBException: The java:comp/env/CLDB reference of type javax.persistence.EntityManager for the null component in the CoplinkRestService.war module of the CoplinkRestService application cannot be resolved.
[ERROR ] SRVE0777E: Exception thrown by application class 'org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage:116'
java.lang.RuntimeException: org.apache.cxf.interceptor.Fault: nested exception is: javax.ejb.EJBException: The java:comp/env/CLDB reference of type javax.persistence.EntityManager for the null component in the CoplinkRestService.war module of the CoplinkRestService application cannot be resolved.
at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:116)
at [internal classes]
Caused by: org.apache.cxf.interceptor.Fault: nested exception is: javax.ejb.EJBException: The java:comp/env/CLDB reference of type javax.persistence.EntityManager for the null component in the CoplinkRestService.war module of the CoplinkRestService application cannot be resolved.
at org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:163)
... 1 more
Caused by: javax.ejb.EJBTransactionRolledbackException: nested exception is: javax.ejb.EJBException: The java:comp/env/CLDB reference of type javax.persistence.EntityManager for the null component in the CoplinkRestService.war module of the CoplinkRestService application cannot be resolved.
at com.ibm.ejs.container.BusinessExceptionMappingStrategy.mapCSIException(BusinessExceptionMappingStrategy.java:127)
at [internal classes]
at com.ibm.coplink.enterprise.details.person.EJSLocalNSLPersonDetailsEJB_df3bc29f.getPersonDetails(EJSLocalNSLPersonDetailsEJB_df3bc29f.java)
at com.ibm.coplink.enterprise.details.DetailsHandlerEJB$$Lambda$8.000000001A297440.apply(Unknown Source)
at com.ibm.coplink.enterprise.details.DetailsHandlerEJB.getDetails(DetailsHandlerEJB.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:495)
at com.ibm.ejs.container.EJSContainer.invokeProceed(EJSContainer.java:5323)
at [internal classes]
at com.ibm.coplink.enterprise.details.EJSLocalNSLDetailsHandlerEJB_c56b7144.getDetails(EJSLocalNSLDetailsHandlerEJB_c56b7144.java)
at com.ibm.coplink.service.CoplinkRestServiceImpl.deleteMe(CoplinkRestServiceImpl.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:495)
at com.ibm.ws.jaxrs20.server.LibertyJaxRsServerFactoryBean.performInvocation(LibertyJaxRsServerFactoryBean.java:607)
... 1 more
Caused by: javax.ejb.EJBException: The java:comp/env/CLDB reference of type javax.persistence.EntityManager for the null component in the CoplinkRestService.war module of the CoplinkRestService application cannot be resolved.
at com.ibm.wsspi.injectionengine.InjectionBinding.getInjectionObject(InjectionBinding.java:1494)
... 18 more
my persistence.xml entries :
<?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="CLDB">
<jta-data-source>coplink-database</jta-data-source>
<properties>
<property name="eclipselink.logging.level" value="ALL"/>
<property name="eclipselink.logging.parameters" value="true"/>
</properties>
</persistence-unit>
<persistence-unit name="CL_ADMIN">
<jta-data-source>coplink-admin-database</jta-data-source>
<properties>
<property name="eclipselink.logging.level" value="ALL"/>
<property name="eclipselink.logging.parameters" value="true"/>
</properties>
</persistence-unit>
</persistence>
my server.xml entries :
<dataSource id="coplink-database" jndiName="coplink-database" statementCacheSize="20" type="javax.sql.ConnectionPoolDataSource">
<properties.microsoft.sqlserver databaseName="Coplink_DemoCLDB_4.8.1.0" password="cldb_password" portNumber="1433" user="cldb_user"/>
<connectionManager agedTimeout="-1" connectionTimeout="30s" maxIdleTime="30m" maxPoolSize="100" minPoolSize="10" reapTime="15m"/>
<jdbcDriver>
<library description="SQLServerDriver" name="SQLServerDriver">
<!-- Relative path to JDBC Driver. Eg. wlp/usr/servers/COPLINKSearchAPIandUI/resources/sqljdbc41.jar -->
<file name="resources/sqljdbc41.jar"/>
</library>
</jdbcDriver>
</dataSource>
<dataSource id="coplink-admin-database" jndiName="coplink-admin-database" statementCacheSize="20" type="javax.sql.ConnectionPoolDataSource">
<properties.microsoft.sqlserver databaseName="Coplink_DemoAdmin_4.8.1.0" password="cldb_password" portNumber="1433" user="cldb_user"/>
<connectionManager agedTimeout="-1" connectionTimeout="30s" maxIdleTime="30m" maxPoolSize="100" minPoolSize="10" reapTime="15m"/>
<jdbcDriver>
<library description="SQLServerDriver" name="SQLServerDriver">
<!-- Relative path to JDBC Driver. Eg. wlp/usr/servers/COPLINKSearchAPIandUI/resources/sqljdbc41.jar -->
<file name="resources/sqljdbc41.jar"/>
</library>
</jdbcDriver>
</dataSource>
my java reference :
#PersistenceContext(name = "CLDB")
private EntityManager cldbManager;
You should be using #PersistenceContext(unitName="CLDB"). The name is only used to control the java:comp/env/ name. The unitName is optional until you have a second <persistence-unit>, and then you need to specify which unit you want.
(The CWWJP0029E message seems like poor serviceability since it shows the persistence unit with two spaces, so it actually means the "" persistence unit. This should probably be reported to IBM to either fix or remove this error message in this case.)

Eclispelink PersistenceUnitLoadingException

i encountered PersistenceUnitLoadingException with Eclispelink 2.4.1 below, what do the stack traces tell?
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: sun.misc.Launcher$AppClassLoader#45a877
Internal Exception: Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: sun.misc.Launcher$AppClassLoader#45a877
Internal Exception: java.lang.NullPointerException
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:127)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:118)
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
at com.mypkg.Main.<clinit>(Main.java:12)
Caused by: Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: sun.misc.Launcher$AppClassLoader#45a877
Internal Exception: java.lang.NullPointerException
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:127)
at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.findPersistenceArchives(PersistenceUnitProcessor.java:321)
at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.findPersistenceArchives(PersistenceUnitProcessor.java:272)
at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.findPersistenceUnitInfoInArchives(JPAInitializer.java:150)
at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.findPersistenceUnitInfo(JPAInitializer.java:135)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:76)
... 3 more
Caused by: java.lang.NullPointerException
at org.eclipse.persistence.internal.jpa.deployment.DirectoryArchive.init(DirectoryArchive.java:79)
at org.eclipse.persistence.internal.jpa.deployment.DirectoryArchive.init(DirectoryArchive.java:96)
at org.eclipse.persistence.internal.jpa.deployment.DirectoryArchive.<init>(DirectoryArchive.java:74)
at org.eclipse.persistence.internal.jpa.deployment.DirectoryArchive.<init>(DirectoryArchive.java:54)
at org.eclipse.persistence.internal.jpa.deployment.ArchiveFactoryImpl.createArchive(ArchiveFactoryImpl.java:89)
at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.findPersistenceArchives(PersistenceUnitProcessor.java:297)
... 7 more
Could not find the main class: com.mypkg.Main. Program will exit.
#EDIT
i have the project structure under Eclipse below, which works well with Hibernate as the persistence provider.
bin
|_META-INF
| |_persistence.xml
|_com
|_mypkg
|_Main.class
|_MyEntity.class
Upgrading to eclipselink to the following resolved this issue for me:
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa</artifactId>
<version>2.7.3</version>
</dependency>