2012-07-12 60 views
2

我想在JBoss AS 7.1.1.Final中为MongoDB使用EclipseLink NoSql持久性。通过EclipseLink实现的MongoDB持久性NoSql JBoss AS 7.1.1.Final

我试图使用EntityManager,如:

EntityManager em = Persistence.createEntityManagerFactory("mongo") 
      .createEntityManager(); 

    Model m = new Model(); 
    em.getTransaction().begin(); 
    em.persist(m); 
    em.getTransaction().commit(); 

这里是我的persistence.xml

<?xml version="1.0" encoding="UTF-8" ?> 
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"> 
    <persistence-unit name="mongo" transaction-type="RESOURCE_LOCAL"> 
     <class>com.Model</class> 
     <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> 
     <properties> 
     <property name="eclipselink.ddl-generation" value="dorop-and=create=tables" /> 
      <property name="eclipselink.target-database" 
       value="org.eclipse.persistence.nosql.adapters.mongo.MongoPlatform" /> 
      <property name="eclipselink.nosql.connection-spec" 
       value="org.eclipse.persistence.nosql.adapters.mongo.MongoConnectionSpec" /> 
      <property name="eclipselink.logging.level" value="FINEST" /> 

     </properties> 
    </persistence-unit> 
</persistence> 

我加入的EclipseLink模块到我的JBoss的安装使用说明书规定here。我还在EclipseLink modules.xml中添加了javax.resource.jar作为依赖项,并为javax.resource创建了一个JBoss模块。 如果有任何方法可以避免将模块添加到JBoss中,而是将其放入我的战争中,那么请让我知道。

这是我目前遇到的问题,这很奇怪,因为我知道它正在加载javax.resource.jar(在没有它之前我得到了一个不同的错误)以及缺少的javax.resource.cci.ConnectionFactory类在那里。

1:35,286 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/barebones].[com.Servlet]] (http-localhost-127.0.0.1-8080-1) Servlet.service() for servlet com.Servlet threw exception: javax.persistence.PersistenceException: java.lang.NoClassDefFoundError: javax/resource/cci/ConnectionFactory 
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:602) [eclipselink-2.4.0.jar:2.4.0.v20120608-r11652] 
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getDatabaseSession(EntityManagerFactoryDelegate.java:186) [eclipselink-2.4.0.jar:2.4.0.v20120608-r11652] 
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:278) [eclipselink-2.4.0.jar:2.4.0.v20120608-r11652] 
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:304) [eclipselink-2.4.0.jar:2.4.0.v20120608-r11652] 
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:282) [eclipselink-2.4.0.jar:2.4.0.v20120608-r11652] 
    at com.Servlet.doGet(Servlet.java:22) [classes:] 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final] 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final] 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:] 
    at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final] 
    at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final] 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:] 
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:] 
    at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_31] 
Caused by: java.lang.NoClassDefFoundError: javax/resource/cci/ConnectionFactory 
    at org.eclipse.persistence.eis.EISConnectionSpec.connectToDataSource(EISConnectionSpec.java:146) [eclipselink-2.4.0.jar:2.4.0.v20120608-r11652] 
    at org.eclipse.persistence.nosql.adapters.mongo.MongoConnectionSpec.connectToDataSource(MongoConnectionSpec.java:150) [org.eclipse.persistence.nosql_2.4.0.v20120608-r11652.jar:] 
    at org.eclipse.persistence.eis.EISLogin.connectToDatasource(EISLogin.java:73) [eclipselink-2.4.0.jar:2.4.0.v20120608-r11652] 
    at org.eclipse.persistence.internal.databaseaccess.DatasourceAccessor.connectInternal(DatasourceAccessor.java:330) [eclipselink-2.4.0.jar:2.4.0.v20120608-r11652] 
    at org.eclipse.persistence.internal.databaseaccess.DatasourceAccessor.connect(DatasourceAccessor.java:418) [eclipselink-2.4.0.jar:2.4.0.v20120608-r11652] 
    at org.eclipse.persistence.sessions.server.ConnectionPool.buildConnection(ConnectionPool.java:216) [eclipselink-2.4.0.jar:2.4.0.v20120608-r11652] 
    at org.eclipse.persistence.sessions.server.ConnectionPool.startUp(ConnectionPool.java:504) [eclipselink-2.4.0.jar:2.4.0.v20120608-r11652] 
    at org.eclipse.persistence.sessions.server.ServerSession.connect(ServerSession.java:484) [eclipselink-2.4.0.jar:2.4.0.v20120608-r11652] 
    at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:734) [eclipselink-2.4.0.jar:2.4.0.v20120608-r11652] 
    at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:215) [eclipselink-2.4.0.jar:2.4.0.v20120608-r11652] 
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:542) [eclipselink-2.4.0.jar:2.4.0.v20120608-r11652] 
    ... 21 more 
Caused by: java.lang.ClassNotFoundException: javax.resource.cci.ConnectionFactory from [Module "org.eclipse.persistence:main" from local module loader @2b76e552 (roots: /usr/jboss/jboss-as-7.1.1.Final/modules)] 
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190) 
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468) 
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456) 
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:423) 
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398) 
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120) 
    ... 32 more 
+0

最近将添加到persistence.xml并将eclipselink.jar添加到JBoss模块 - 更新了包版块。 – 2012-07-14 02:33:11

+0

错误是因为加载类时无法找到ResourceException类。这是因为EclipseLink尝试使用应用程序类加载器加载“MongoPlatform”类,然后在使用它创建新实例时发生异常。不幸的是,缺少的ResourceException类意味着实际的异常不能被抛出。尝试确保将javax.resource添加为EclipseLink模块依赖项 – Chris 2012-07-16 16:32:28

+0

@Chris - Man ...上周我做了这个,但是我弄糟了javax/resource的modules.xml。更新了包版并添加了步骤。谢谢! – 2012-07-16 16:53:34

回答

0

有同样的问题。 请将“< module name =”javax.resource.api“/>” “添加到org.eclipse.persistence的module.xml中的依赖关系中。

它为我工作。

相关问题