开发者

JPA 2 with managed transactions not persisting object

I'm using the OpenJPA implementation of JPA 2 and am having problems persisting an object to the database. I want to use transactions managed by the container (Websphere), so my understanding is that, since the transactions are managed, they boilerplate code like tx.begin(), tx.commit(), etc aren't needed.

 <?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="buildTest" transaction-type="JTA">
        <jta-data-source>jdbc/lfcbuild</jta-data-source>
        <class>entities.Build</class>
        <properties>
            <property name="openjpa.jdbc.Schema" value="APP"/>
            <property name="openjpa.TransactionMode" value="managed"/>
            <property name="openjpa.ConnectionFactoryMode" value="managed"/>                    
        </properties>
    </persistence-unit>
</persistence>

The code I'm executing when persisting a build is this:

EntityManagerFactory emf = Persistence.createEntityManagerFactory("buildTest");
EntityManager em = emf.createEntityManager();

Build b = new Build();
b.setFirstName("Dick");
b.setLastName("Tracy");

em.persist(b);

The code runs, and throws no exceptions. When I check the database, nothing has been persisted. Am I missing something, or should this be enough开发者_高级运维 for the object to persist with container managed transactions?


Is that code part of an EJB? Otherwise you might have to start and commit the Tx programmatically.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜