我正在尝试创建一个实体管理器来持久化一个对象。这是我的做法:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("com.dv_model_jar_1.0-SNAPSHOTPU");
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
Users user = new Users();
user.setPassword("test2");
user.setUserName("test2");
tx.begin();
em.persist(user);
tx.commit();
em.close();
emf.close();
当我尝试在 Netbeans 中运行此代码时,我可以执行第一行并获得一个工厂,但是,在执行第二行之后,程序停止了。没有输出。任何想法为什么?
这是我的 persistence.xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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_2_0.xsd">
<persistence-unit name="com.dv_model_jar_1.0-SNAPSHOTPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>com.dv.model.Users</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:8889/esa"/>
<property name="javax.persistence.jdbc.password" value="root"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="eclipselink.ddl-generation" value="create-tables"/>
</properties>