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>
但是我需要什麼來強制否則提交。 –
你需要在你的方法中添加一些事務上下文嗎? – Rick