2

我有两个项目“ProjectA.war”和“ProjectB.war”。

在这两个项目中,我都使用 Oracle 11g、JPA2 和 EclipseLink 2.4.2。我正在使用 JBOSS 5.1.0 GA 应用服务器。

两者都有不同的persistence.xml 文件,具有不同的持久性单元名称,不同的数据源文件。在这里,我为两个项目连接相同的 Oracle DB 用户。

我的问题是...首先我在服务器中部署了 ProjectA.war。它工作正常。和数据库操作也可以正常工作。

现在我在 ProjectA.war 之外的服务器中部署 ProjectB.war。因此,当我尝试在 ProjectA.war 上执行数据库操作时,jboss 正在借助 ProjectB 的持久性单元名称在 ProjectB.war 的 persistenece.xml 文件中搜索 POJO 类。但实际上它需要在ProjectA中搜索。

那么,我能做什么?

我的 ProjectA.war 配置如下...

============ persistence.xml ==================

<persistence 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
persistence_2_0.xsd" version="2.0">

          <persistence-unit name="Entity" transaction-type="RESOURCE_LOCAL">

                    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

                    <non-jta-data-source>java:/projectADS</non-jta-data-source>

                    <class>env.model.authorization.IptUsersRoles</class>

                    <class>env.model.defaults.IptUsergroups</class>
                    <class>env.model.defaults.IptUsertype</class>
                    <class>env.model.authorization.IptUsers</class>

                        <properties>
                              <property name="javax.persistence.jdbc.driver"
                                        value="oracle.jdbc.driver.OracleDriver" />
                              <property name="javax.persistence.jdbc.url"
                                        value="jdbc:oracle:thin:@x.x.x.x:1521:TEST" />
                              <property name="javax.persistence.jdbc.user" value="TEST" />
                              <property name="javax.persistence.jdbc.password" value="TEST" />
                              <property name="eclipselink.session.customizer" value="entity.jpa.JPAEclipseLinkSessionCustomizer"/>
                              <property name="eclipselink.logging.level" value="FINEST"/>
                    </properties>

          </persistence-unit>
</persistence>

================= jboss-classloading.xml ===================

    <?xml version="1.0" encoding="UTF-8"?>
    <classloading xmlns="urn:jboss:classloading:1.0"
                                  name="ProjectA.war" 
                                  domain="DefaultDomain"
                                  top-level-classloader="true"
                                  parent-domain="Ignored"
                export-all="NON_EMPTY"
                import-all="true"
                parent-first="false">
    </classloading>

    ==================== jboss-web.xml ======================

    <?xml version="1.0" encoding="UTF-8"?>
    <jboss-web>
              <resource-ref>
                        <description>DB Connection</description>
                        <res-ref-name>ProjectADS</res-ref-name>
                        <res-type>javax.sql.DataSource</res-type>
                        <jndi-name>java:/ProjectADS</jndi-name>
                        <res-auth>Container</res-auth>
        </resource-ref>
    </jboss-web>

我的 ProjectB.war 配置如下...

============ persistence.xml ==================

<?xml version="1.0" encoding="UTF-8"?>
<persistence 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
    persistence_2_0.xsd" version="2.0">

          <persistence-unit name="IportIBEntity" transaction-type="RESOURCE_LOCAL">

                    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

                    <non-jta-data-source>java:/ProjectBDS</non-jta-data-source>

                    <class>env.model.IptRequestDataRecord</class>
                    <class>env.model.IptResponseDataRecord</class>

                    <properties>
                              <property name="eclipselink.jdbc.driver"
                                        value="oracle.jdbc.driver.OracleDriver" />
                              <property name="eclipselink.jdbc.url"
                                        value="jdbc:oracle:thin:@x.x.x.x:1521:TEST" />
                              <property name="eclipselink.jdbc.user" value="TEST" />
                              <property name="eclipselink.jdbc.password" value="TEST" />
                              <property name="eclipselink.session.customizer"
                                        value="entity.jpa.JPAEclipseLinkSessionCustomizer" />
                              <property name="eclipselink.logging.level" value="FINEST" />
                    </properties>

          </persistence-unit>
</persistence>

================= jboss-classloading.xml ===================

<?xml version="1.0" encoding="UTF-8"?>
<classloading xmlns="urn:jboss:classloading:1.0"
                              name="ProjectB.war" 
                              domain="DefaultDomain"
                              top-level-classloader="true"
                              parent-domain="Ignored"
            export-all="NON_EMPTY"
            import-all="true"
            parent-first="false">
</classloading>


==================== jboss-web.xml ======================

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
          <resource-ref>
                    <description>DB Connection</description>
                    <res-ref-name>ProjectBDS</res-ref-name>
                    <res-type>javax.sql.DataSource</res-type>
                    <jndi-name>java:/ProjectBDS</jndi-name>
                    <res-auth>Container</res-auth>
    </resource-ref>
</jboss-web>

和下面的控制台错误....

13:26:34,068 INFO  [IportIBEntity] finding IptUsers instance with property: userCode, value: ADMIN
13:26:34,709 SEVERE [IportIBEntity] find by property name failed
java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: 
Exception Description: Problem compiling [select model from IptUsers model where model.userCode= :propertyValue]. 
[18, 26] The abstract schema type 'IptUsers' is unknown.
[39, 53] The state field path 'model.userCode' cannot be resolved to a valid type.
          at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1512)
          at env.acegi.users.IptUsersDAO.findByProperty(IptUsersDAO.java:174)
          at env.acegi.users.IptUsersDAO.findByUserCode(IptUsersDAO.java:185)
          at env.acegi.security.AcegiAuthentication.loadUserByUsername(AcegiAuthentication.java:51)
          at org.acegisecurity.providers.dao.DaoAuthenticationProvider.retrieveUser(DaoAuthenticationProvider.java:99)
          at org.acegisecurity.providers.dao.AbstractUserDetailsAuthenticationProvider.authenticate(AbstractUserDetailsAuthenticationProvider.java:122)
          at org.acegisecurity.providers.ProviderManager.doAuthentication(ProviderManager.java:200)
          at org.acegisecurity.AbstractAuthenticationManager.authenticate(AbstractAuthenticationManager.java:47)
          at org.acegisecurity.ui.webapp.AuthenticationProcessingFilter.attemptAuthentication(AuthenticationProcessingFilter.java:74)
          at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:252)
          at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
          at org.acegisecurity.ui.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
          at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
          at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:249)
          at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
          at org.acegisecurity.concurrent.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:95)
          at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
          at org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:149)
          at org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:98)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
          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: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.4.2.v20130315-93567e3): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Problem compiling [select model from IptUsers model where model.userCode= :propertyValue]. 
[18, 26] The abstract schema type 'IptUsers' is unknown.
[39, 53] The state field path 'model.userCode' cannot be resolved to a valid type.
          at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildException(HermesParser.java:150)
          at org.eclipse.persistence.internal.jpa.jpql.HermesParser.validate(HermesParser.java:339)
          at org.eclipse.persistence.internal.jpa.jpql.HermesParser.populateQueryImp(HermesParser.java:270)
          at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildQuery(HermesParser.java:157)
          at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:138)
          at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:112)
          at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:98)
          at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:82)
          at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1510)
          ... 38 more
13:26:34,711 ERROR [[default]] Servlet.service() for servlet default threw exception
java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: 
Exception Description: Problem compiling [select model from IptUsers model where model.userCode= :propertyValue]. 
[18, 26] The abstract schema type 'IptUsers' is unknown.
[39, 53] The state field path 'model.userCode' cannot be resolved to a valid type.
          at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1512)
          at env.acegi.users.IptUsersDAO.findByProperty(IptUsersDAO.java:174)
          at env.acegi.users.IptUsersDAO.findByUserCode(IptUsersDAO.java:185)
          at env.acegi.security.AcegiAuthentication.loadUserByUsername(AcegiAuthentication.java:51)
          at org.acegisecurity.providers.dao.DaoAuthenticationProvider.retrieveUser(DaoAuthenticationProvider.java:99)
          at org.acegisecurity.providers.dao.AbstractUserDetailsAuthenticationProvider.authenticate(AbstractUserDetailsAuthenticationProvider.java:122)
          at org.acegisecurity.providers.ProviderManager.doAuthentication(ProviderManager.java:200)
          at org.acegisecurity.AbstractAuthenticationManager.authenticate(AbstractAuthenticationManager.java:47)
          at org.acegisecurity.ui.webapp.AuthenticationProcessingFilter.attemptAuthentication(AuthenticationProcessingFilter.java:74)
          at org.acegisecurity.ui.AbstractProcessingFilter.doFilter(AbstractProcessingFilter.java:252)
          at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
          at org.acegisecurity.ui.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
          at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
          at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:249)
          at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
          at org.acegisecurity.concurrent.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:95)
          at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:275)
          at org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:149)
          at org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:98)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
          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: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.4.2.v20130315-93567e3): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Problem compiling [select model from IptUsers model where model.userCode= :propertyValue]. 
[18, 26] The abstract schema type 'IptUsers' is unknown.
[39, 53] The state field path 'model.userCode' cannot be resolved to a valid type.
          at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildException(HermesParser.java:150)
          at org.eclipse.persistence.internal.jpa.jpql.HermesParser.validate(HermesParser.java:339)
          at org.eclipse.persistence.internal.jpa.jpql.HermesParser.populateQueryImp(HermesParser.java:270)
          at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildQuery(HermesParser.java:157)
          at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:138)
          at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:112)
          at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:98)
          at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:82)
          at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1510)
          ... 38 more

在上面的错误描述中......

"INFO  [IportIBEntity] finding IptUsers instance with property: userCode, value: ADMIN"

这里 IportIBEntity 是 ProjectB.war 的持久化单元,但 IptUsers pojo 在 ProjectA.war 中有。因此,它试图在 ProjectB.war 而不是 ProjectA.war 中搜索 pojo

我也闲置了以下链接,但没有进展

JBoss5 中的 JBoss Web 类加载器

请帮我解决问题....

4

0 回答 0