struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Arun <arun.george.1...@gmail.com>
Subject Re: detached object cannot be persisted exception again
Date Mon, 09 Jun 2008 12:32:35 GMT
Sorry I was away. I will surely try this.

On 6/5/08, Martin <mgainty@hotmail.com> wrote:
>
> Arun-
>
> did you disable the optimistic_lock code..?
>  // OPTIMISTIC LOCK MODE (dont use this as this causes OptimisticLockMode
> Exceptions)
> // Attribute olNode = node.attribute( "optimistic-lock" );
> //return Versioning.OPTIMISTIC_LOCK_VERSION;
>
> // entity.setOptimisticLockMode( getOptimisticLockMode( olNode ) );
>
> //try a dirty lock..
> Attribute dirtyNode = node.attribute( "optimistic-lock-dirty");
>
> entity.setOptimisticLockMode( getOptimisticLockMode(dirtyNode) );
>
> //or lock all
> Attribute lockAllNode = node.attribute( "optimistic-lock-all");
>
> entity.setOptimisticLockMode( getOptimisticLockMode(lockAllNode) );
>
> //or No lock
> Attribute lockNoneNode = node.attribute( "optimistic-lock-none");
> entity.setOptimisticLockMode( getOptimisticLockMode(lockNoneNode) );
>
> HTH,
> Martin
> ----- Original Message ----- From: "Arun" <arun.george.1981@gmail.com>
> To: "Struts Users Mailing List" <user@struts.apache.org>
> Sent: Thursday, June 05, 2008 12:11 PM
> Subject: detached object cannot be persisted exception again
>
>
> Hi,
>>
>> I am using JPA and ehcache.
>> My entity is this.
>>
>> @Entity
>> @Table(name = "holiday_calendar")
>> @Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
>> public class HolidaysCalendar
>> {
>> @Id
>> @Column(name = "HOLIDAY_CALENDAR_ID", nullable = false, unique = true)
>> private int holidayCalendarId;
>>
>> @Column(name = "DATE", nullable = false)
>> private Date date;
>>
>> @Column(name = "TYPE", nullable = false)
>> private String type;
>>
>> @Column(name = "DESCRIPTION", nullable = true)
>> private String description;
>>
>> ---
>>
>>
>> }
>>
>>
>> when I try to do an entityManager.merge(holidaycalendarobj)
>> First call I am succesful, next tine I get the exception
>> persistenceexception: detached object cannot be persisted.
>> I am using openSessionInViewFilter and spring.
>> I have tried using saveOrUpdate() of hibernate.
>> I got another exception then.
>>
>> My log told me this by which I am confused. Please help
>> javax.persistence.RollbackException: Error while commiting the transaction
>> at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:71)
>> at
>>
>> org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:433)
>> at
>>
>> org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:651)
>> at
>>
>> org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:621)
>> at
>>
>> org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:311)
>> at
>>
>> org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:117)
>> at
>>
>> org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161)
>> at
>>
>> org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:628)
>> at
>>
>> com.slingmedia.emp.facade.employee.LeaveManager$$EnhancerByCGLIB$$5a2b3b92.createHoliday(<generated>)
>> at
>>
>> com.slingmedia.emp.web.actions.employee.LeaveManagerAction.addHolidays(LeaveManagerAction.java:568)
>> 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
>>
>> com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:404)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:267)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:229)
>> at
>>
>> com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:221)
>> at
>>
>> com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>> at
>>
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>> at
>>
>> com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:150)
>> at
>>
>> org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:48)
>> at
>>
>> com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>> at
>>
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>> at
>>
>> com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:123)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>> at
>>
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>> at
>>
>> com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:167)
>> at
>>
>> com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>> at
>>
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>> at
>>
>> com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:105)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>> at
>>
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>> at
>>
>> org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:83)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>> at
>>
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>> at
>>
>> org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:207)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>> at
>>
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>> at
>>
>> com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:74)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>> at
>>
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>> at
>>
>> com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:127)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>> at
>>
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>> at
>>
>> org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:107)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>> at
>>
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>> at
>>
>> org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:206)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>> at
>>
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>> at
>>
>> com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:115)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>> at
>>
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>> at
>>
>> com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:143)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>> at
>>
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>> at
>>
>> com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:121)
>> at
>>
>> com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>> at
>>
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>> at
>>
>> org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:170)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>> at
>>
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>> at
>>
>> com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:123)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>> at
>>
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>> at
>>
>> com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:224)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:223)
>> at
>>
>> com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
>> at
>>
>> com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:221)
>> at
>>
>> org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:50)
>> at
>>
>> org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:504)
>> at
>>
>> org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
>> at
>>
>> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
>> at
>>
>> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
>> 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:202)
>> at
>>
>> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
>> at
>>
>> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
>> at
>>
>> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
>> at
>>
>> org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:524)
>> at
>>
>> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
>> at
>>
>> org.apache.catalina.cluster.tcp.ReplicationValve.invoke(ReplicationValve.java:346)
>> at
>>
>> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
>> at
>>
>> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
>> at
>>
>> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
>> at
>> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
>> at
>>
>> org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
>> at
>>
>> org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
>> at
>>
>> org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
>> at
>>
>> org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
>> at java.lang.Thread.run(Thread.java:595)
>> Caused by: javax.persistence.OptimisticLockException:
>> org.hibernate.StaleStateException: Batch update returned unexpected row
>> count from update [0]; actual row count: 0; expected: 1
>> at
>>
>> org.hibernate.ejb.AbstractEntityManagerImpl.wrapStaleStateException(AbstractEntityManagerImpl.java:654)
>> at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:59)
>> ... 129 more
>> Caused by: org.hibernate.StaleStateException: Batch update returned
>> unexpected row count from update [0]; actual row count: 0; expected: 1
>> at
>>
>> org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:61)
>> at
>>
>> org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:46)
>> at
>> org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:68)
>> at
>> org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
>> at
>> org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
>> at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
>> at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)
>> at
>>
>> org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
>> at
>>
>> org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
>> at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
>> at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
>> at
>> org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
>> at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:54)
>> ... 129 more
>>
>>
>>
>> Does any body has a soultion.I know this is becuase I use persist and
>> secondlevel cache together.
>> I am checking if the entity already exists in db. So the argument that I
>> am
>> trying to persist an already existing entity itself is wrong.
>> My guess is the cache is not synching with db or something of that sort.
>> I have enabled query caching and is using that.
>> Is it becuase of that?
>>
>> public List<HolidaysCalendar> getHolidaysCalendarForYear(int year, String
>> type)
>> {
>> Query query = null;
>>
>> if ( "-1".equals(type) )
>> {
>> query = entityManager.createQuery("select hcal from HolidaysCalendar hcal
>> where YEAR(hcal.date) = :year ");
>> }
>> else
>> query = entityManager.createQuery("select hcal from HolidaysCalendar hcal
>> where YEAR(hcal.date) = :year and hcal.type= :type");
>>
>> query.setHint("org.hibernate.cacheable", true);
>> //query.setHint("org.hibernate.timeout", 24 * 60 * 60);// 1 day cache.
>> query.setParameter("year", year);
>> if ( !"-1".equals(type) )
>> query.setParameter("type", type);
>> return query.getResultList();
>> }
>>
>>
>>
>> Is query level caching affecting this or some sort of things like that?
>> Please help!!!
>>
>>
>> --
>> Thanks
>> Arun George
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


-- 
Thanks
Arun George

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message