Hi. I'm having a problem using the Hibernate JPA implementation with Spring transactions / Tomcat. I think the following code should throw a TransactionRequiredException if save is called when not in a transaction.
Code:
public class MyObjDAO {
@PersistenceContext(type=PersistenceContextType.TRANSACTION)
private EntityManager em;
public void save(MyObj obj) {
em.persist(obj);
}
}
However, no exception is thrown, and the application is completely unaware that nothing gets saved to the database.
Looking at how org.hibernate.ejb.EntityManagerFactoryImpl is implemented it seems it will always set the type to EXTENDED.
Code:
public EntityManager createEntityManager(Map map) {
//TODO support discardOnClose, persistencecontexttype?, interceptor,
return new EntityManagerImpl(
this, PersistenceContextType.EXTENDED, transactionType,
discardOnClose, sessionInterceptorClass, map
);
}
From the code it looks like persistencecontexttype will always be EXTENDED for EntityManager objects created using the EntityManagerFactory.
Can anyone confirm this? If so this would seem to be a bug.
I'm using hibernate 3.5 b4 with Spring 3.0.1's LocalContainerEntityManagerFactoryBean and I'm guessing there is a good chance this is in fact a bug in Spring. It's not clear to me which out of Spring / Hibernate is responsible for processing the PersistenceContext annotation so if anyone could explain this that would be great also.