I am using hibernate 3.6 (JPA interface) , Spring 3.0.3 , and the Spring JpaTransactionManager. Whenever I do a entityManager.find() I can see hibernate firing a SQL query but on persist I don't see a update or insert . Please find the library versions, code and my findings below. Any pointers would be highly appreciated.....
thanks,
Parag
- Before a transactional method is called “TransactionSynchronizationManager.bindResource” sets the EntityManager (with an associated transaction ) as ThreadLocal. (stack 1)
- “EntityManagerFactoryUtils.doGetTransactionalEntit yManager()” is called when a “entityManager.find/ createNamedQuery/persist ” is done from application code. (stack 2)
- This in turn tries to get the transactional EntityManager from ThreadLocal and doesnot find it… (am not sure what removes it, and this seems to be the problem..) and creates a new EntityManager which does not have a transaction associated
- when entityManager.persist() is called the insert is not done since there is not transaction associated with the EntityManager (stack 3)
1. Stack before business method is called
2. Stack when EntityManager.find / createNamedQuery / is calledCode:TransactionSynchronizationManager.bindResource(Object, Object) line: 170 JpaTransactionManager.doBegin(Object, TransactionDefinition) line: 357 JpaTransactionManager(AbstractPlatformTransactionManager).getTransaction(TransactionDefinition) line: 371 TransactionInterceptor(TransactionAspectSupport).createTransactionIfNecessary(PlatformTransactionManager, TransactionAttribute, String) line: 316 TransactionInterceptor.invoke(MethodInvocation) line: 105
3. stack when entityManager.persist() is called.Code:TransactionSynchronizationManager.getResource(Object) line: 136 EntityManagerFactoryUtils.doGetTransactionalEntityManager(EntityManagerFactory, Map) line: 167 SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(Object, Method, Object[]) line: 211 $Proxy144.find(Class, Object) line: not available DataSourceDaoImpl.getProviderTypeById(int) line: not available DataSourceDaoImpl.saveProviderType(DataProviderType) line: not available DataSourceDaoImpl$$FastClassByCGLIB$$e55fce5f.invoke(int, Object, Object[]) line: not available MethodProxy.invoke(Object, Object[]) line: 191 Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint() line: 688 Cglib2AopProxy$CglibMethodInvocation(ReflectiveMethodInvocation).proceed() line: 150 TransactionInterceptor.invoke(MethodInvocation) line: 110 Cglib2AopProxy$CglibMethodInvocation(ReflectiveMethodInvocation).proceed() line: 172 Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Object, Method, Object[], MethodProxy) line: 621 DataSourceDaoImpl$$EnhancerByCGLIB$$335c347.saveProviderType(DataProviderType) line: not available AssessmentUserFavoritesSetHandler.handleRequest(AssessmentUserFavoritesSetRequest) line: 40
Code:EJB3PersistEventListener(AbstractSaveEventListener).performSaveOrReplicate(Object, EntityKey, EntityPersister, boolean, Object, EventSource, boolean) line: 263 EJB3PersistEventListener(AbstractSaveEventListener).performSave(Object, Serializable, EntityPersister, boolean, Object, EventSource, boolean) line: 203 EJB3PersistEventListener(AbstractSaveEventListener).saveWithGeneratedId(Object, String, Object, EventSource, boolean) line: 129 EJB3PersistEventListener.saveWithGeneratedId(Object, String, Object, EventSource, boolean) line: 69 EJB3PersistEventListener(DefaultPersistEventListener).entityIsTransient(PersistEvent, Map) line: 179 EJB3PersistEventListener(DefaultPersistEventListener).onPersist(PersistEvent, Map) line: 135 EJB3PersistEventListener(DefaultPersistEventListener).onPersist(PersistEvent) line: 61 SessionImpl.firePersist(PersistEvent) line: 808 SessionImpl.persist(String, Object) line: 782 SessionImpl.persist(Object) line: 786 EntityManagerImpl(AbstractEntityManagerImpl).persist(Object) line: 672 NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method] NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39 DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25 Method.invoke(Object, Object...) line: 597 ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(Object, Method, Object[]) line: 365 $Proxy179.persist(Object) line: not available NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method] NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39 DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25 Method.invoke(Object, Object...) line: 597 SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(Object, Method, Object[]) line: 240 $Proxy144.persist(Object) line: not available DataSourceDaoImpl.saveProviderType(DataProviderType) line: not available DataSourceDaoImpl$$FastClassByCGLIB$$e55fce5f.invoke(int, Object, Object[]) line: not available MethodProxy.invoke(Object, Object[]) line: 191 Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint() line: 688 Cglib2AopProxy$CglibMethodInvocation(ReflectiveMethodInvocation).proceed() line: 150 TransactionInterceptor.invoke(MethodInvocation) line: 110 Cglib2AopProxy$CglibMethodInvocation(ReflectiveMethodInvocation).proceed() line: 172 Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Object, Method, Object[], MethodProxy) line: 621 DataSourceDaoImpl$$EnhancerByCGLIB$$335c347.saveProviderType(DataProviderType) line: not available AssessmentUserFavoritesSetHandler.handleRequest(AssessmentUserFavoritesSetRequest) line: 40 AssessmentUserFavoritesSetHandler.handleRequest(APIRequest) line: 27


Reply With Quote
