openJPA配置不持久

时间:2017-08-10 13:42:55

标签: openjpa glassfish-4 openjpa-maven-plugin

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

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>

1 个答案:

答案 0 :(得分:0)

我猜你的交易没有被提交。