EntityManagerFactory.createEntityManager() - 非关系平台不支持此操作

时间:2012-06-29 14:18:19

标签: mongodb eclipselink java-ee-6 nosql

我正在研究https://blogs.oracle.com/arungupta/entry/java_ee_6_and_nosql的例子。

以下是模型src http://dev.eclipse.org/svnroot/rt/org.eclipse.persistence/trunk/examples/org.eclipse.persistence.example.jpa.nosql.mongo/src/

的链接

导致我出现问题的部分是:

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

当调用org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager时我得到了

SEVERE: javax.persistence.PersistenceException: Exception [EclipseLink-7108] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.ValidationException
Exception Description: This operation is not supported for non-relational platforms.

以下是我正在使用的所有依赖项:

<classpath>
  <classpathentry kind="src" path="src/main/java" including="**/*.java"/>
  <classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/>
  <classpathentry kind="output" path="target/classes"/>
  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
  <classpathentry kind="var" path="M2_REPO/javax/javaee-web-api/6.0/javaee-web-api-6.0.jar"/>
  <classpathentry kind="var" path="M2_REPO/com/sun/jersey/jersey-server/1.8/jersey-server-1.8.jar"/>
  <classpathentry kind="var" path="M2_REPO/asm/asm/3.1/asm-3.1.jar"/>
  <classpathentry kind="var" path="M2_REPO/com/sun/jersey/jersey-core/1.8/jersey-core-1.8.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/mongodb/mongo-java-driver/2.7.3/mongo-java-driver-2.7.3.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/eclipse/persistence/org.eclipse.persistence.oracle.nosql/2.4.0/org.eclipse.persistence.oracle.nosql-2.4.0.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/eclipse/persistence/javax.persistence/2.0.4.v201112161009/javax.persistence-2.0.4.v201112161009.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/eclipse/persistence/org.eclipse.persistence.asm/3.3.1.v201206041142/org.eclipse.persistence.asm-3.3.1.v201206041142.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/eclipse/persistence/org.eclipse.persistence.antlr/3.2.0.v201206041011/org.eclipse.persistence.antlr-3.2.0.v201206041011.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/eclipse/persistence/org.eclipse.persistence.jpa.jpql/2.4.0/org.eclipse.persistence.jpa.jpql-2.4.0.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/eclipse/persistence/org.eclipse.persistence.core/2.4.0/org.eclipse.persistence.core-2.4.0.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/eclipse/persistence/org.eclipse.persistence.nosql/2.4.0/org.eclipse.persistence.nosql-2.4.0.jar"/>
  <classpathentry kind="var" path="M2_REPO/org/eclipse/persistence/org.eclipse.persistence.jpa/2.4.0/org.eclipse.persistence.jpa-2.4.0.jar"/>
</classpath>

服务器是GlassFish Server开源版3.我无法弄清楚为什么不能允许createEntityManager,当我从为其他人工作的示例代码复制它时?

1 个答案:

答案 0 :(得分:1)

该异常显示EclipseLink构建为2.0.1.v20100213-r6600,而此功能需要EclipseLink 2.4或更高版本。无论您如何设置依赖项,它似乎都在使用Glassfish附带的EclipseLink版本。您可以尝试更换/升级这些捆绑包,如下所述: https://blogs.oracle.com/GlassFishPersistence/entry/updating_eclipselink_bundles_in_glassfish