无法获取数据源。不能在JBoss 5.1中使用JPA EntityManager(EclipseLink)

时间:2012-07-19 17:24:25

标签: jpa jboss eclipselink jboss5.x

我将JBA(EclipseLink)放在JBoss服务器上面临很多困难。我通常使用Tomcat,这很简单......

  1. 我将/jboss-5.1.0.GA/docs/examples/jca中的mysql-ds.xml复制到/jboss-5.1.0.GA/servers/default/deploy/然后我对其进行了配置。
  2. mysql-ds.xml文件:

    <?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. 然后我在我的WebApplication中配置了persistence.xml。
    2. 的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>
      

      结局我实例化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());
      }
      

      当我部署它时,我的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
      

      我试过很多不同的方法,但我不能把这些工作。

      任何人都可以帮助我吗?

3 个答案:

答案 0 :(得分:3)

我找到了解决方案。

JBoss强制我们定义非jta-data-source 如果我们不想使用事务或 jta-data-source ,如果你想用它..

无论哪种方式,无论我们是否想要使用交易,问题在于提供的大部分信息建议我们使用 jdbc / JNDI-NAME 指定这些信息时我们想要使用的是的的java:/ JNDI-NAME

总之,如果您想使用带有JBoss的EclipseLink JPA而不是Data-Source,您需要确保指定:

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

以下是对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>

感谢您的宝贵帮助@Chris。

答案 1 :(得分:1)

您正在指定不与数据源混合的“javax.persistence.jdbc.x”属性。您应该指定要使用的数据源,或JDBC连接URL等,但不能同时指定两者。你在尝试使用JTA吗?还有一个警告声明您正在使用带有JTA数据源的transaction-type =“resource-local” - 您需要为要使用的JTA数据源指定“JTA”事务类型,并且将需要它以便它可以挂钩到JBoss事务管理器。数据源查找可能还需要设置目标服务器。

答案 2 :(得分:0)

我知道这可能很老了。我在使用jdeveloper 12c和weblogic 12.x时遇到了同样的问题 我通过从persistence.xml文件的数据源名称中省略 java:来解决此问题,如下所示:  从: java:/ app / jdbc / data_source

至: / app / jdbc / data_source