Cannot acquire data source. Can't Use JPA EntityManager (EclipseLink) with JBoss 5.1
Asked Answered
E

3

6

I'm facing a lot of difficulties to put the JPA (EclipseLink) working in the JBoss Server. I normally use Tomcat and it's quite simple...

  1. I copied the mysql-ds.xml from /jboss-5.1.0.GA/docs/examples/jca to /jboss-5.1.0.GA/servers/default/deploy/ and then I configured it.

mysql-ds.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<datasources>
  <local-tx-datasource>
    <jndi-name>EDeliveryUnit</jndi-name>
    <connection-url>jdbc:mysql://localhost:3306/edelivery_db</connection-url>
    <driver-class>com.mysql.jdbc.Driver</driver-class>
    <user-name>root</user-name>
    <password>root</password>
    <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
    <check-valid-connection-sql>SELECT * FROM systemuser</check-valid-connection-sql>
    <metadata>
       <type-mapping>mySQL</type-mapping>
    </metadata>
  </local-tx-datasource>
</datasources>
  1. Then I configured the persistence.xml in my WebApplication.

persistence.xml:

<?xml version="1.0" encoding="UTF-8" ?>
<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"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="edeliveryPU"
    transaction-type="RESOURCE_LOCAL">
    <jta-data-source>jdbc/EDeliveryUnit</jta-data-source>
    <non-jta-data-source>jdbc/EDeliveryUnit</non-jta-data-source>
    <class>pt.inov.spocs.board.server.model.entity.SystemUser</class>
    <class>pt.inov.spocs.board.server.model.entity.UserSession</class>
    <properties>
        <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
        <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/edelivery_db" />
        <property name="javax.persistence.jdbc.user" value="root" />
        <property name="javax.persistence.jdbc.password" value="root" />
        <property name="eclipselink.jdbc.batch-writing" value="JDBC" />
        <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
    </properties>
</persistence-unit>

Finale I instantiate the EntityManager:

private EntityManagerFactory emf;
private EntityManager em;

public Controller() {
    System.out.println("Begin..");

    emf = Persistence.createEntityManagerFactory("edeliveryPU");
    em = emf.createEntityManager();

    user = em.find(SystemUser.class, new Long(1));
    System.out.println("Username: " + user.getUsername() + " | pass: "
            + user.getPassword());
}

When I deploy it I got these error in my jboss:

2012-07-20 13:22:15,762 INFO  [STDOUT] (http-127.0.0.1-8080-1) Begin..
2012-07-20 13:22:16,346 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Config]: The access type for the persistent class [class pt.inov.spocs.board.server.model.entity.UserSession] is set to [FIELD].
2012-07-20 13:22:16,414 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Config]: The target entity (reference) class for the many to one mapping element [field user] is being defaulted to: class pt.inov.spocs.board.server.model.entity.SystemUser.
2012-07-20 13:22:16,417 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Config]: The access type for the persistent class [class pt.inov.spocs.board.server.model.entity.SystemUser] is set to [FIELD].
2012-07-20 13:22:16,419 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Config]: The alias name for the entity class [class pt.inov.spocs.board.server.model.entity.UserSession] is being defaulted to: UserSession.
2012-07-20 13:22:16,424 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Config]: The table name for entity [class pt.inov.spocs.board.server.model.entity.UserSession] is being defaulted to: USERSESSION.
2012-07-20 13:22:16,468 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Config]: The column name for element [sessionKey] is being defaulted to: SESSIONKEY.
2012-07-20 13:22:16,470 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Config]: The column name for element [endDate] is being defaulted to: ENDDATE.
2012-07-20 13:22:16,472 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Config]: The column name for element [beginDate] is being defaulted to: BEGINDATE.
2012-07-20 13:22:16,472 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Config]: The column name for element [ip] is being defaulted to: IP.
2012-07-20 13:22:16,474 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Config]: The alias name for the entity class [class pt.inov.spocs.board.server.model.entity.SystemUser] is being defaulted to: SystemUser.
2012-07-20 13:22:16,475 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Config]: The table name for entity [class pt.inov.spocs.board.server.model.entity.SystemUser] is being defaulted to: SYSTEMUSER.
2012-07-20 13:22:16,476 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Config]: The column name for element [id] is being defaulted to: ID.
2012-07-20 13:22:16,477 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Config]: The column name for element [username] is being defaulted to: USERNAME.
2012-07-20 13:22:16,477 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Config]: The column name for element [password] is being defaulted to: PASSWORD.
2012-07-20 13:22:16,479 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Config]: The pk column value for the table generator named [SystemUserGenerator] defined on [class pt.inov.spocs.board.server.model.entity.SystemUser] from [class pt.inov.spocs.board.server.model.entity.SystemUser] is being defaulted to: SystemUserGenerator.
2012-07-20 13:22:16,526 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Config]: The primary key column name for the mapping element [field user] is being defaulted to: ID.
2012-07-20 13:22:16,526 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Config]: The foreign key column name for the mapping element [user] is being defaulted to: USER_ID.
2012-07-20 13:22:16,696 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Warning]: PersistenceUnitInfo edeliveryPU has transactionType RESOURCE_LOCAL and therefore jtaDataSource will be ignored
2012-07-20 13:22:16,700 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Info]: EclipseLink, version: Eclipse Persistence Services - 2.3.2.v20111125-r10461
2012-07-20 13:22:16,716 INFO  [STDOUT] (http-127.0.0.1-8080-1) [EL Severe]: Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [java:/EDeliveryUnit].
Internal Exception: javax.naming.InvalidNameException: Not a compound name: EDeliveryUnit
2012-07-20 13:22:16,717 SEVERE [org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage] (http-127.0.0.1-8080-1) Error Rendering View[/index.xhtml]
javax.el.ELException: /index.xhtml: Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [java:/EDeliveryUnit].
Internal Exception: javax.naming.InvalidNameException: Not a compound name: EDeliveryUnit
at org.apache.myfaces.view.facelets.compiler.TextInstruction.write(TextInstruction.java:57)
at org.apache.myfaces.view.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:46)
at org.apache.myfaces.view.facelets.compiler.UILeaf.encodeAll(UILeaf.java:214)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:614)
at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.renderView(FaceletViewDeclarationLanguage.java:1159)
at org.apache.myfaces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:263)
at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:85)
at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:239)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:191)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:662)
Caused by: 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:/EDeliveryUnit].
Internal Exception: javax.naming.InvalidNameException: Not a compound name: EDeliveryUnit
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 pt.inov.spocs.board.server.model.entity.Controller.<init>(Controller.java:19)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at org.apache.myfaces.config.annotation.TomcatAnnotationLifecycleProvider.newInstance(TomcatAnnotationLifecycleProvider.java:49)
at org.apache.myfaces.config.ManagedBeanBuilder.buildManagedBean(ManagedBeanBuilder.java:162)
at org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.createManagedBean(ManagedBeanResolver.java:303)
at org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.getValue(ManagedBeanResolver.java:266)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:142)
at org.apache.myfaces.el.VariableResolverImpl.resolveVariable(VariableResolverImpl.java:65)
at org.apache.myfaces.el.convert.VariableResolverToELResolver.getValue(VariableResolverToELResolver.java:96)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:142)
at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:61)
at org.apache.el.parser.AstValue.getValue(AstValue.java:107)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
at org.apache.myfaces.view.facelets.el.ELText$ELTextVariable.writeText(ELText.java:213)
at org.apache.myfaces.view.facelets.el.ELText$ELTextComposite.writeText(ELText.java:125)
at org.apache.myfaces.view.facelets.compiler.TextInstruction.write(TextInstruction.java:48)
... 28 more
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:/EDeliveryUnit].
Internal Exception: javax.naming.InvalidNameException: Not a compound name: EDeliveryUnit
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)
... 55 more
Caused by: javax.naming.InvalidNameException: Not a compound name: EDeliveryUnit
at javax.naming.CompoundName.addAll(CompoundName.java:445)
at org.jnp.interfaces.NamingContext.composeName(NamingContext.java:1077)
at org.jnp.interfaces.NamingContext.getAbsoluteName(NamingContext.java:1855)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:717)
at javax.naming.InitialContext.lookup(InitialContext.java:396)
at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:103)
... 59 more
2012-07-20 13:22:16,764 SEVERE [org.apache.myfaces.renderkit.ErrorPageWriter] (http-127.0.0.1-8080-1) An exception occurred
javax.faces.FacesException: 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:/EDeliveryUnit].
Internal Exception: javax.naming.InvalidNameException: Not a compound name: EDeliveryUnit
at org.apache.myfaces.shared_impl.context.ExceptionHandlerImpl.wrap(ExceptionHandlerImpl.java:241)
at org.apache.myfaces.shared_impl.context.ExceptionHandlerImpl.handle(ExceptionHandlerImpl.java:156)
at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:258)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:191)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:662)
Caused by: 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:/EDeliveryUnit].
Internal Exception: javax.naming.InvalidNameException: Not a compound name: EDeliveryUnit
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 pt.inov.spocs.board.server.model.entity.Controller.<init>(Controller.java:19)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at org.apache.myfaces.config.annotation.TomcatAnnotationLifecycleProvider.newInstance(TomcatAnnotationLifecycleProvider.java:49)
at org.apache.myfaces.config.ManagedBeanBuilder.buildManagedBean(ManagedBeanBuilder.java:162)
at org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.createManagedBean(ManagedBeanResolver.java:303)
at org.apache.myfaces.el.unified.resolver.ManagedBeanResolver.getValue(ManagedBeanResolver.java:266)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:142)
at org.apache.myfaces.el.VariableResolverImpl.resolveVariable(VariableResolverImpl.java:65)
at org.apache.myfaces.el.convert.VariableResolverToELResolver.getValue(VariableResolverToELResolver.java:96)
at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
at org.apache.myfaces.el.unified.resolver.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:142)
at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:61)
at org.apache.el.parser.AstValue.getValue(AstValue.java:107)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
at org.apache.myfaces.view.facelets.el.ELText$ELTextVariable.writeText(ELText.java:213)
at org.apache.myfaces.view.facelets.el.ELText$ELTextComposite.writeText(ELText.java:125)
at org.apache.myfaces.view.facelets.compiler.TextInstruction.write(TextInstruction.java:48)
at org.apache.myfaces.view.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:46)
at org.apache.myfaces.view.facelets.compiler.UILeaf.encodeAll(UILeaf.java:214)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:614)
at org.apache.myfaces.view.facelets.FaceletViewDeclarationLanguage.renderView(FaceletViewDeclarationLanguage.java:1159)
at org.apache.myfaces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:263)
at org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:85)
at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:239)
... 21 more
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:/EDeliveryUnit].
Internal Exception: javax.naming.InvalidNameException: Not a compound name: EDeliveryUnit
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)
... 55 more
   Caused by: javax.naming.InvalidNameException: Not a compound name: EDeliveryUnit
at javax.naming.CompoundName.addAll(CompoundName.java:445)
at org.jnp.interfaces.NamingContext.composeName(NamingContext.java:1077)
at org.jnp.interfaces.NamingContext.getAbsoluteName(NamingContext.java:1855)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:717)
at javax.naming.InitialContext.lookup(InitialContext.java:396)
at org.eclipse.persistence.sessions.JNDIConnector.connect(JNDIConnector.java:103)
... 59 more

I tried in many different ways but I can't put these working.

Anyone can help me please?

Endogenous answered 19/7, 2012 at 17:24 Comment(0)
E
6

I found the solution.

JBoss force us to define a non-jta-data-source if we don't want to use transactions or a jta-data-source if you want to use it..

Either way no matter if we want to use transactions, the problem is that most of the information provided advise us to specify these with a jdbc/JNDI-NAME when what we want to use is a java:/JNDI-NAME.

In conclusion, if you want to use a EclipseLink JPA with JBoss instead of Data-Source you need to ensure that you are specifying the:

  • transaction-type="RESOURCE_LOCAL"
  • <non-jta-data-source>java:/JNDI-NAME</non-jta-data-source> or <jta-data-source>java:/JNDI-NAME</jta-data-source>

Here is the correction of my persistence.xml:

<persistence-unit name="persistenceSamplePU" transaction-type="RESOURCE_LOCAL">     
     <non-jta-data-source>java:/EDeliveryUnit</non-jta-data-source>

     <!-- Entities must be specified for EclipseLink weaving -->
    <class>pt.inov.spocs.board.server.model.entity.SystemUser</class>
    <class>pt.inov.spocs.board.server.model.entity.UserSession</class>

    <properties>
        <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
        <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/edelivery_db" />
        <property name="javax.persistence.jdbc.user" value="root" />
        <property name="javax.persistence.jdbc.password" value="root" />
    </properties>
</persistence-unit>

Thank you for your precious help @Chris.

Endogenous answered 25/7, 2012 at 10:51 Comment(0)
C
1

You are specifying "javax.persistence.jdbc.x" properties which do not mix with datasources. You should specify the datasource to use, or the JDBC connection url etc but not both. Are you trying to use JTA? There is also a warning stating you are using transaction-type="resource-local" with a JTA datasource defined - you need to specify the "JTA" transaction type for the JTA datasource to be used, and the will be needed so it can hook into the JBoss transaction manager. Setting the target server might also be needed for the datasource lookup.

Convene answered 20/7, 2012 at 16:8 Comment(3)
Yes, I think I'm mixing both and I just want to use the JDBC. But if I doesn't specify the datasource my server throws me the exception java.lang.RuntimeException: Specification violation [EJB3 JPA 6.2.1.2] - You have not defined a jta-data-source for a JTA enabled persistence context named: edeliveryPU What do you mean by "Are you trying to use JTA?" At the moment I just want to configure a simple example of JPA with persistence.xml and EntityManager avoiding the ctx.lookup("jdbc/MySQLDS");Endogenous
If you are not using JTA and don't want datasources used, then do not define them in your persistence.xml. I find it strange that JBoss would complain about a lack of JTA when the pu says it is using transaction-type="RESOURCE_LOCAL", and the <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> tag isn't shown so it should be using the default persistence provider. Is there another persistence.xml with the same persistence unit name being picked up?Convene
Nop. But I found the problem. I had to define the non-jta-data-souce in the persistence.xml like that: <non-jta-data-source>java:/EDeliveryUnit</non-jta-data-source>. I already had tried in many different ways but instead of java:/ I used jdbc/Endogenous
D
0

I know this might be old. I faced same issue with jdeveloper 12c and weblogic 12.x I fixed this by omitting java: from datasource name at persistence.xml file as follows: from: java:/app/jdbc/data_source

to: /app/jdbc/data_source

Decillion answered 26/6, 2018 at 16:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.