persistence.xml忽略Hibernate并选择DataNucleus

时间:2010-02-18 12:32:43

标签: java hibernate gwt jpa datanucleus

我正在玩GWT(dunno,如果这很重要)和Hibernate。我在META-INF中创建了一个文件persistence.xml,其中包含(amoung)其他配置: org.hibernate.ejb.HibernatePersistence 但是当我启动EntityManager时,它会选择DataNucleus而不是Hibernate(后来因为没有安装而失败(jar不在类路径中))

Java代码是:

EntityManagerFactory factory = Persistence.createEntityManagerFactory("gwt");
EntityManager em =factory.createEntityManager();
EntityTransaction transacation = em.getTransaction();
transacation.begin();
Campaign campaign = new Campaign();
campaign.setName("Test");
em.persist(campaign);
transacation.commit();

配置文件包含:

<?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
  http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
  version="1.0">
  <persistence-unit name="gwt" transaction-type="JTA">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>java:/DefaultDS</jta-data-source>
      <properties>
  ...

3 个答案:

答案 0 :(得分:0)

那么告诉我,你在GAE / J上使用它吗? DataNucleus显然在CLASSPATH中,因为它在你的日志中就是这样说的。

答案 1 :(得分:0)

Google Plugin for Eclipse 文档中引用Creating a New Web Application部分:

  

使用新的Web应用程序向导创建项目

     

“新建Web应用程序项目”向导   允许您创建新的Web   使用Google Web的应用程序   工具包(GWT)和/或Google App   发动机:

     

alt text

您是否在项目创建时选择使用Google App Engine ?如果是,请不要。

答案 2 :(得分:0)

我使用了错误的JPA Wrapper类。之前我使用的是geronimo-jpa.jar,最后我使用了Glassfish的javax-persistance.jar。 Dunno,如果这是一个甜蜜的解决方案,但至少它是一个。