Writes are committed immediately during a JPA/JTA transaction in EAP

Solution In Progress - Updated -

Issue

  • A persistence unit is configured as below
    <persistence-unit name="MyTestUnit" transaction-type="JTA">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        ...
        <properties>
            <property name="hibernate.connection.driver_class" value="..." />
            <property name="hibernate.connection.url" value="..." />
            <property name="hibernate.connection.username" value="..." />
            <property name="hibernate.connection.password" value="..." />
            <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
            ...
        </properties>
    </persistence-unit>
  • A transaction executes as below
    txMgr.begin();

    // Hook the entity manager into transaction events (e.g. commit) - not required in most environments
    entityManager.joinTransaction();

    // Write is not immediate on the persist() call, it is deferred until the first flush
    entityManager.persist(new Event("meeting"));

    // A committed write occurs in the process of executing the query below
    entityManager.createQuery("from Event").getResultList().size();

    // This rollback has no effect
    txMgr.rollback();

    // The assertion fails due to the write above
    Assert.assertEquals(0, entityManager.createQuery("from Event").getResultList().size());

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 4
    • 5
    • 6
  • Hibernate
    • 3
    • 4

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content