2017-08-10 57 views
0

我有一个非常简单的测试,可以正确配置openJPA,JTA,数据库连接,增强功能,并且不会发出任何异常,但它不会保留在下面的简单代码中。除了简单的语句之外,我还需要展示什么或者什么是必要的,才能真正将记录写入数据库?openJPA配置为不存在

public class Manipulation00 { 
    public Manipulation00(){} 
    public void startUp(ServletContext sc){ 
       EntityManagerFactory emf = 
      (EntityManagerFactory)sc.getAttribute("emf"); 
     EntityManager em = emf.createEntityManager(); 
     Exemptions00 exempt00 = new Exemptions00(); 
     exempt00.setUpc("722430001166"); 
     exempt00.setDesc("KOMBUCHA,OG2,SEASONAL"); 
     em.persist(exempt00); 
    } 

} 

persistence.xml中

<?xml version="1.0" encoding="UTF-8"?> 
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> 
    <persistence-unit name="ediExemptions" transaction-type="JTA"> 
     <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider> 
     <jta-data-source>java:app/ediExemptions</jta-data-source> 
     <class>tng.db02.Exemptions00</class> 
     <properties> 
      <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/> 
      <property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO"/> 
      <property name="openjpa.jdbc.SynchronizeMappings" 
         value="buildSchema"/> 
      <property name="openjpa.ConnectionURL" 
         value="jdbc:derby://localhost:1527/ediExemptions"/> 
      <property name="openjpa.ConnectionDriverName" 
         value="org.apache.derby.jdbc.ClientDriver"/> 
      <property name="openjpa.ConnectionUserName" 
         value="root"/> 
      <property name="openjpa.ConnectionPassword" 
         value="admin"/> 
     </properties> 
    </persistence-unit> 
</persistence> 

回答

0

我猜想,您的交易没有被提交。

+0

但是我需要什么来强制否则提交。 –

+0

你需要在你的方法中添加一些事务上下文吗? – Rick