0

I am trying to persist a simple entity but it is not persisted to database without any error. I am using glassfish 3.1.2, hibernate 4.1.3.Final, transaction scoped/container managed entitymanager. jta transactions is configured in persistence.xml and jta datasource is set correctly. It is a stateless session bean with default transaction level(REQUIRED). In the console, I am seeing "Skipping JTA sync registration due to auto join checking" message several times from Hibernate's TransactionCoordinatorImp. I could find a manually inserted entity using entitymanager.find. But could not persist or merge. Any idea on what could be the problem?

Update:It seems that problem is not related to "Skipping JTA sync registration due to auto join checking" message. If I set transaction isolation level to REQUIRES_NEW new entity is added, but if I set isolation level to REQUIRED it is not persisted. This method was the first one that receives the jax-rs web service call. Why do I need REQUIRES_NEW isolation level?

Deniz
  • 1,575
  • 1
  • 16
  • 27

1 Answers1

2

You have not given nearly enough detail about your set up so I can only answer in general.

The skipping sync registration bit actually does play into this. This is part of what JPA calls transaction joining. The basic principal is that an EntityManager is not allowed (by spec) to automatically participate in transactions that were not active at the time it was created. In psuedo code, its the difference between:

// start transaction
// create EntityManager
// use EntityManager
// commit transaction

and:

// create EntityManager
// start transaction
// use EntityManager
// commit transaction

In the first case, the EntiytManager is created within the scope of the active transaction, so it automatically joins. In the second case, it is created outside the scope of the active transaction, so it cannot automatically join.

In such cases EntityManager.joinTransaction() must be called to have the EntityManager participate in the transaction:

// create EntityManager
// start transaction
entityManager.joinTransaction();
// use EntityManager
// commit transaction

This is the situation you find yourself in. You just need to find out how/why the EntityManager is being created outside the scope of a transaction if that is not what you are expecting.

Steve Ebersole
  • 9,339
  • 2
  • 48
  • 46
  • 1
    Although I have only used J2EE stateless bean and @PersistenceContext annotation to inject EM, seam-persistence-3.1.0 and seam-transaction-3.1.0 jars where causing above problem. I have removed them from the classpath and the messsage has gone. I think there is a compatibility problem with seam-transaction and hibernate. – Deniz Jun 22 '12 at 05:36