openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adish Abnave <adish...@yahoo.com>
Subject Re: Help - TransactionRequiredException while calling entityManager.lock(). Using Sprin's Declarative Transaction Management
Date Mon, 29 Oct 2007 19:11:59 GMT
Yes, The editEntity() method is transactional. I am using Spring Declarative Transaction management,
@Transactional annotation and i am sure all the configurations are correct.

-Adish


 
---------------------------------------------------------------
"Luck is what happens when preparation meets opportunity"
---------------------------------------------------------------

----- Original Message ----
From: Patrick Linskey <plinskey@gmail.com>
To: users@openjpa.apache.org
Sent: Monday, October 29, 2007 11:38:13 AM
Subject: Re: Help - TransactionRequiredException while calling entityManager.lock(). Using
Sprin's Declarative Transaction Management

So, boiling this down to your code, we have:

>     at
 com.inxight.mdr.dao.impl.DocumentDAOImpl.updateVersion(DocumentDAOImpl.java:452)
>     ...
>     at
 com.inxight.ta.app.service.impl.EntityServiceImpl.editEntity(EntityServiceImpl.java:555)
>     at
 com.inxight.ta.app.struts.actions.EntityAction.edit(EntityAction.java:364)

Is editEntity() a transactional method?

Based on the exception, it sounds like OpenJPA's transaction is indeed
not active, which is necessary for a lock to be obtained. Note that
merge() can be called outside of an active transaction.

-Patrick


On 10/29/07, Adish Abnave <adish_27@yahoo.com> wrote:
> Below is the full stack trace
>
> 03:53:35,328 22840367 DEBUG
 (org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:100))
 - Opening JPA EntityManager in OpenEntityManagerInViewFilter
> 03:53:35,328 22840367 DEBUG
 (org.springframework.transaction.support.TransactionSynchronizationManager.bindResource(TransactionSynchronizationManager.java:168))
 - Bound value [org.springframework.orm.jpa.EntityManagerHolder@10772d2]
 for key
 [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean@4c5b3] to thread [http-8081-Processor24]
> 03:53:35,328 22840367 DEBUG
 (org.springframework.web.struts.DelegatingActionUtils.determineActionBeanName(DelegatingActionUtils.java:166))
-
 DelegatingActionProxy with mapping path '/entity' and module prefix ''
 delegating to Spring bean with name [/entity]
> 03:53:35,343 22840382 DEBUG
 (org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:203))
-
 Returning cached instance of singleton bean '/entity'
> 03:53:35,343 22840382 DEBUG
 (org.springframework.transaction.support.TransactionSynchronizationManager.getResource(TransactionSynchronizationManager.java:140))
 - Retrieved value
 [org.springframework.orm.jpa.EntityManagerHolder@10772d2] for key
 [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean@4c5b3] bound to thread
[http-8081-Processor24]
> 03:53:35,390 22840429 DEBUG
 (org.springframework.transaction.support.TransactionSynchronizationManager.getResource(TransactionSynchronizationManager.java:140))
 - Retrieved value
 [org.springframework.orm.jpa.EntityManagerHolder@10772d2] for key
 [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean@4c5b3] bound to thread
[http-8081-Processor24]
> 03:53:36,109 22841148 DEBUG
 (org.springframework.transaction.support.TransactionSynchronizationManager.getResource(TransactionSynchronizationManager.java:140))
 - Retrieved value
 [org.springframework.orm.jpa.EntityManagerHolder@10772d2] for key
 [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean@4c5b3] bound to thread
[http-8081-Processor24]
> 03:53:36,109 22841148 DEBUG
 (org.springframework.transaction.support.TransactionSynchronizationManager.getResource(TransactionSynchronizationManager.java:140))
 - Retrieved value
 [org.springframework.orm.jpa.EntityManagerHolder@10772d2] for key
 [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean@4c5b3] bound to thread
[http-8081-Processor24]
> 03:53:36,125 22841164 ERROR
 (com.inxight.ta.app.struts.exceptions.BaseExceptionHandler.logException(BaseExceptionHandler.java:145))
-
 org.springframework.dao.InvalidDataAccessApiUsageException: Can only perform
 operation while a transaction is active.; nested exception is
 <openjpa-1.0.0-r420667:570500M nonfatal user error>
 org.apache.openjpa.persistence.TransactionRequiredException: Can only perform operation while
a
 transaction is active.
> Caused by: <openjpa-1.0.0-r420667:570500M nonfatal user error>
 org.apache.openjpa.persistence.TransactionRequiredException: Can only perform
 operation while a transaction is active.
>     at
 org.apache.openjpa.kernel.BrokerImpl.assertActiveTransaction(BrokerImpl.java:4312)
>     at
 org.apache.openjpa.kernel.BrokerImpl.lock(BrokerImpl.java:3528)
>     at
 org.apache.openjpa.kernel.DelegatingBroker.lock(DelegatingBroker.java:1233)
>     at
 org.apache.openjpa.persistence.EntityManagerImpl.lock(EntityManagerImpl.java:887)
>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     at
 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>     at
 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>     at java.lang.reflect.Method.invoke(Method.java:585)
>     at
 org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:340)
>     at $Proxy59.lock(Unknown Source)
>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     at
 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>     at
 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>     at java.lang.reflect.Method.invoke(Method.java:585)
>     at
 org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:180)
>     at $Proxy6.lock(Unknown Source)
>     at
 com.inxight.mdr.dao.impl.DocumentDAOImpl.updateVersion(DocumentDAOImpl.java:452)
>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     at
 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>     at
 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>     at java.lang.reflect.Method.invoke(Method.java:585)
>     at
 org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:296)
>     at
 org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:177)
>     at
 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
>     at
 org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:138)
>     at
 org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
>     at
 org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
>     at $Proxy9.updateVersion(Unknown Source)
>     at
 com.inxight.ta.app.service.impl.EntityServiceImpl.editEntity(EntityServiceImpl.java:555)
>     at
 com.inxight.ta.app.struts.actions.EntityAction.edit(EntityAction.java:364)
>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     at
 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>     at
 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>     at java.lang.reflect.Method.invoke(Method.java:585)
>     at
 org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:274)
>     at
 org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:194)
>     at
 com.inxight.ta.app.struts.actions.BaseAction.execute(BaseAction.java:70)
>     at
 org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110)
>     at
 org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
>     at
 org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
>     at
 org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
>     at
 org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
>     at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
>     at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>     at
 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
>     at
 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
>     at
 com.inxight.ta.app.filters.EncodingFilter.doFilter(EncodingFilter.java:80)
>     at
 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
>     at
 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
>     at
 org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:111)
>     at
 org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
>     at
 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
>     at
 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
>     at
 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
>     at
 org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
>     at
 org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
>     at
 org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
>     at
 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
>     at
 org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
>     at
 org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
>     at
 org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
>     at
 org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
>     at
 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
>     at
 org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
>     at
 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
>     at
 org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
>     at
 org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
>     at
 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
>     at
 org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
>     at
 org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
>     at
 org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
>     at
 org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
>     at
 org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
>     at
 org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
>     at
 org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
>     at
 org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
>     at java.lang.Thread.run(Thread.java:595)
>
>
> ---------------------------------------------------------------
> "Luck is what happens when preparation meets opportunity"
> ---------------------------------------------------------------
>
> ----- Original Message ----
> From: Patrick Linskey <plinskey@gmail.com>
> To: users@openjpa.apache.org
> Sent: Monday, October 29, 2007 8:32:55 AM
> Subject: Re: Help - TransactionRequiredException while calling
 entityManager.lock(). Using Sprin's Declarative Transaction Management
>
> Hi,
>
> Can you post the full stack trace?
>
> Thanks,
>
> -Patrick
>
> On 10/29/07, Adish Abnave <adish_27@yahoo.com> wrote:
> > I have deployed my web app in Tomcat container.Below is my app
>  context,
> >
> >
> >
> > <bean id="entityManagerFactory"
>  class="org.springframework.orm.jpa.LocalContainerE
  ntityManagerFactoryBean">
> >
> >         <property name="dataSource" ref="dataSource"/>
> >
> >         <property name="jpaVendorAdapter">
> >
> >             <bean
 class="org.springframework.orm.jpa.vendor.OpenJpaV
>   endorAdapter">
> >
> >                 <property name="showSql" value="false"/>
> >
> >                 <property name="generateDdl" value="true"/>
> >
> >                 <property name="databasePlatform"
>  value="org.apache.openjpa.jdbc.sql.OracleDictionar  y"/>
> >
> >             </bean>
> >
> >         </property>
> >
> >         <property name="jpaPropertyMap">
> >
> >             <map>
> >
> >                 <entry key="openjpa.jdbc.DBDictionary"
>  value="org.apache.openjpa.jdbc.sql.OracleDictionar  y"/>
> >
> >                 <entry key="openjpa.Log" value="DefaultLevel=WARN,
>  Runtime=TRACE, SQL=TRACE"/>
> >
> >             </map>
> >
> >         </property>
> >
> >         <property name="loadTimeWeaver">
> >
> >             <bean
 class="org.springframework.instrument.classloading
>   .SimpleLoadTimeWeaver"/>
> >
> >         </property>
> >
> >     </bean>
> >
> >
> >
> >     <bean id="jpaTemplate"
>  class="org.springframework.orm.jpa.JpaTemplate">
> >
> >         <property name="entityManagerFactory"
>  ref="entityManagerFactory"/>
> >
> >     </bean>
> >
> >
> >
> >     <bean name="transactionManager"
>  class="org.springframework.orm.jpa.JpaTransactionM  anager">
> >
> >         <property name="entityManagerFactory"
>  ref="entityManagerFactory" />
> >
> >         <property name="dataSource" ref="dataSource"/>
> >
> >     </bean>
> >
> >
> >
> >     <tx:annotation-driven />
> >
> >
> >
> > I am using Spring's OpenEntityManagerinView filter as below in my
>  web.xml,
> >
> >  <filter>
> >
> >         <filter-name>JpaFilter</filter-name>
> >
> >         <filter-class>org.springframework.orm.jpa.support.OpenEnti
>   tyManagerInViewFilter</filter-class>
> >
> >     </filter>
> >
> >
> >
> >     <filter-mapping>
> >
> >         <filter-name>JpaFilter</filter-name>
> >
> >         <url-pattern>*.do</url-pattern>
> >
> >     </filter-mapping>
> >
> >  All my service implementation methods are marked @Transactional.
> >
> >
> >
> > I get a TransactionRequiredException when calling
>  entityManager.lock(entity); method
> >
> > I am able to successfully merge() entities and my persistence
 context
>  type is the default "Transaction..."
> >
> > When i debug, entitymanager.getTransaction() throws a
> > IllegalStateException and entityManager.getTransactionalObjects()
> > returns an empty collection.
> >
> > Is the Transaction never started ?
> >
> > How do  check this?
> >
> >
> >
> > Any help will be greatly appreciated.
> > ---------------------------------------------------------------
> > "Luck is what happens when preparation meets opportunity"
> > ---------------------------------------------------------------
> >
> >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam protection around
> > http://mail.yahoo.com
>
>
> --
> Patrick Linskey
> 202 669 5907
>
>
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com


-- 
Patrick Linskey
202 669 5907





__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message