我正在玩弄 GWT(不知道这是否重要)和 Hibernate。我已经在 META-INF 中创建了一个文件 persistence.xml 与(以及)其他配置行: 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>
...