6

将 JPA (EclipseLink) 放在 JBoss 服务器中工作时,我遇到了很多困难。我通常使用Tomcat,它很简单......

  1. 我将 mysql-ds.xml 从 /jboss-5.1.0.GA/docs/examples/jca 复制到 /jboss-5.1.0.GA/servers/default/deploy/ 然后我配置它。

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。

持久性.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

我尝试了许多不同的方式,但我无法让这些工作。

任何人都可以帮助我吗?

4

3 回答 3

6

我找到了解决方案。

如果我们不想使用事务,JBoss 强制我们定义一个非 jta- data-source,如果你想使用它,则强制我们定义一个 jta-data-source。

无论哪种方式,无论我们是否要使用事务,问题是提供的大多数信息都建议我们使用jdbc/JNDI-NAME来指定这些,而我们要使用的是java:/JNDI-NAME

总之,如果您想将 EclipseLink JPA 与 JBoss 而不是 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。

于 2012-07-25T10:51:08.163 回答
1

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

于 2012-07-20T16:08:30.350 回答
0

我知道这可能是旧的。我在 jdeveloper 12c 和 weblogic 12.x 上遇到了同样的问题,我通过省略java: from datasource name at persistence.xml 文件解决了这个问题,如下所示:from: java:/app/jdbc/data_source

到: /app/jdbc/data_source

于 2018-06-26T16:41:44.677 回答