Announcement Announcement Module
Collapse
No announcement yet.
Shared EntityManager with Hibernate in WebLogic Server Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Shared EntityManager with Hibernate in WebLogic Server

    I have a problem trying to get a SharedEntityManager for the life of a JTA transaction. I'm using hibernate-entitymanager-3.2.1.ga, spring-2.0.4 and WebLogic 9.2MP1 with org.springframework.orm.jpa.LocalContainerEntityMa nagerFactoryBean and org.springframework.transaction.jta.WebLogicJtaTra nsactionManager.

    I believe Spring should be acting as the container from the JPA perspective, correctly scoping a SharedEntityManager for the duration of the underlying JTA transaction. A SharedEntityManager is being injected into my DAOs as a 'holder', however a new EntityManager delegate is being used for each transactional method. From a code inspection, this appears to be due to the EntityManagerSynchronization.beforeCompletion() method being invoked for each of these transactional methods even though they are part of an overall JTA transaction. As seen below, this method removes the EntityManager if it thinks it created it (newEntityManager == true).

    Code:
    public void beforeCompletion() {
    	if (this.newEntityManager) {
    		TransactionSynchronizationManager.unbindResource(this.entityManagerFactory);
    		this.holderActive = false;
    		this.entityManagerHolder.getEntityManager().close();
    	}
    }
    That approach will only work when requesting an EntityManager in a scope that is nested within an existing scope.

    Shouldn't the

    Code:
    TransactionSynchronizationManager.unbindResource(this.entityManagerFactory);
    be left until the end of the JTA transaction?

    Why is beforeCompletion() being called for each transactional method instead of just once for the JTA transaction?
Working...
X