Reputation: 45
I'm migrating a JPA application from an old version of EclipseLink to Hibernate 5.4.9.Final.
In EclipseLink, the EntityManager FlushMode was configured to COMMIT
, via the following property in persistence.xml
:
<property name="eclipselink.persistence-context.flush-mode" value="COMMIT"/>
I try to do the same in Hibernate, and as per the documentation, I use the following property:
<property name="org.hibernate.flushMode" value="COMMIT" />
but hibernate does not pick it up.
I have to mention that the behaviour needs to remain the same, otherwise I should rewrite the whole application. My persistence.xml
looks like this:
...
<persistence-unit name="test">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<!--<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>-->
<class>com.test.Person</class>
<properties>
<property name="org.hibernate.flushMode" value="COMMIT"/>
<!--<property name="eclipselink.persistence-context.flush-mode" value="COMMIT"/>-->
</properties>
</persistence-unit>
...
In my JUnit Test, I bootstrap JPA as follows:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("test", properties);
EntityManager entityManager = emf.createEntityManager();
entityManager.getTransaction().begin();
Session session = entityManager.unwrap(Session.class);
System.out.println("Underlying Hibernate session flushmode ####### " + session.getFlushMode());
System.out.println("EntityManager flushmode ####### " + entityManager.getFlushMode());
If I run the test with EclipseLink, it shows the EntityManager flushmode COMMIT
correctly. If I run the test with Hibernate, the EntityManager flushmode incorrectly shows AUTO
.
What am I doing wrong?
Thank you in advance, Mike
Upvotes: 1
Views: 488