Web sphere Liberty可以管理多个JTA源吗?

时间:2015-09-29 20:31:17

标签: jpa websphere-liberty

当我在persistence.xml中添加一个jta-data-source时,我遇到了运行时异常

[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

我的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="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>

我的server.xml条目:

<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>

我的java参考:

@PersistenceContext(name = "CLDB")
private EntityManager cldbManager;

1 个答案:

答案 0 :(得分:1)

您应该使用@PersistenceContext(unitName="CLDB")name仅用于控制java:comp/env/名称。在您有第二个unitName之前,<persistence-unit>是可选的,然后您需要指定所需的单位。

CWWJP0029E消息似乎很差,因为它显示the persistence unit有两个空格,所以它实际上意味着the "" persistence unit。这可能会报告给IBM修复或删除在这种情况下出现错误消息。)