Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Merge resets new data
Merge resets new data [message #550392] Fri, 30 July 2010 08:54 Go to next message
Alex Ka is currently offline Alex KaFriend
Messages: 4
Registered: July 2010
Location: Sofia, Bulgaria
Junior Member
Hi,
I'm using EclipseLink 2.0.1.v20100213-r6600 on Glassfish v2.1 (JPA 1.0). My description of the problem will be obfuscated but I'll try to explain what I'm observing and I hope to get some comments.

Recently I noticed I problem in the production database of my software. It turned out that on some "Document" entities, the "Status" property didn't get updated to a new value when I was performing merge(). The problem is worsened by the fact that it occurs only in the production system and that is only occasionally.

I debugged one occurrence of the malfunction and noticed that at some point in the merge() call, the new value of the "Status" was reset by Eclipse link. It appeared that the "User" entity that was referenced in the "Document" was involved. It has the following annotations:
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "USER_ID", referencedColumnName = "ID")


The "User" references the "Document"(s) back with the following annotation to the collection:
@OneToMany(mappedBy = "user", cascade = CascadeType.REFRESH)


I traced the problem to the "User" entity at an inner recursive call of:
org.eclipse.persistence.internal.sessions.MergeManager.mergeChanges(MergeManager.java:267)


Obviously some changes where made to the "User" entity and this prompted the merge() of the "Document" to go and execute a reset (refresh) on my "Document"'s "Status" field. Does anyone have an idea why this is happening? A colleague proposed that CascadeType.REFRESH should be omitted but in my opinion this should not influence the fact I have setup a value of my entity and I want it saved. Any comments are welcome...

Here is the full thread dump of the case:
httpSSLWorkerThread-8080-2@116 daemon, prio=10, in group 'Grizzly', status: 'RUNNING'
	  at xxx.Document.setStatus(Document.java:133)
	  at sun.reflect.GeneratedMethodAccessor7616.invoke(Unknown Source:-1)
	  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	  at java.lang.reflect.Method.invoke(Method.java:597)
	  at org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor.setAttributeValueInObject(MethodAttributeAccessor.java:196)
	  at org.eclipse.persistence.mappings.DatabaseMapping.setAttributeValueInObject(DatabaseMapping.java:1367)
	  at org.eclipse.persistence.mappings.foundation.AbstractDirectMapping.buildCloneFromRow(AbstractDirectMapping.java:1218)
	  at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildAttributesIntoWorkingCopyClone(ObjectBuilder.java:1260)
	  at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildWorkingCopyCloneFromRow(ObjectBuilder.java:1381)
	  at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObjectInUnitOfWork(ObjectBuilder.java:547)
	  at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:491)
	  at org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:443)
	  at org.eclipse.persistence.queries.ObjectLevelReadQuery.buildObject(ObjectLevelReadQuery.java:635)
	  at org.eclipse.persistence.queries.ReadAllQuery.registerResultInUnitOfWork(ReadAllQuery.java:838)
	  at org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:464)
	  at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:997)
	  at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:675)
	  at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:958)
	  at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:432)
	  at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1021)
	  at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2857)
	  at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1225)
	  at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1207)
	  at org.eclipse.persistence.internal.indirection.QueryBasedValueHolder.instantiate(QueryBasedValueHolder.java:85)
	  at org.eclipse.persistence.internal.indirection.QueryBasedValueHolder.instantiateForUnitOfWorkValueHolder(QueryBasedValueHolder.java:100)
	  at org.eclipse.persistence.internal.indirection.UnitOfWorkValueHolder.instantiateImpl(UnitOfWorkValueHolder.java:156)
	  at org.eclipse.persistence.internal.indirection.UnitOfWorkValueHolder.instantiate(UnitOfWorkValueHolder.java:230)
	  at org.eclipse.persistence.internal.indirection.DatabaseValueHolder.getValue(DatabaseValueHolder.java:83)
	  at org.eclipse.persistence.indirection.IndirectList.buildDelegate(IndirectList.java:237)
	  at org.eclipse.persistence.indirection.IndirectList.getDelegate(IndirectList.java:397)
	  at org.eclipse.persistence.indirection.IndirectList.size(IndirectList.java:726)
	  at org.eclipse.persistence.internal.queries.CollectionContainerPolicy.sizeFor(CollectionContainerPolicy.java:175)
	  at org.eclipse.persistence.mappings.CollectionMapping.mergeIntoObject(CollectionMapping.java:1347)
	  at org.eclipse.persistence.internal.descriptors.ObjectBuilder.mergeIntoObject(ObjectBuilder.java:2671)
	  at org.eclipse.persistence.internal.sessions.MergeManager.mergeChangesOfCloneIntoWorkingCopy(MergeManager.java:506)
	  at org.eclipse.persistence.internal.sessions.MergeManager.mergeChanges(MergeManager.java:267)
	  at org.eclipse.persistence.mappings.ObjectReferenceMapping.mergeIntoObject(ObjectReferenceMapping.java:419)
	  at org.eclipse.persistence.internal.descriptors.ObjectBuilder.mergeIntoObject(ObjectBuilder.java:2671)
	  at org.eclipse.persistence.internal.sessions.MergeManager.mergeChangesOfCloneIntoWorkingCopy(MergeManager.java:506)
	  at org.eclipse.persistence.internal.sessions.MergeManager.mergeChanges(MergeManager.java:267)
	  at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.mergeCloneWithReferences(UnitOfWorkImpl.java:3480)
	  at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.mergeCloneWithReferences(RepeatableWriteUnitOfWork.java:301)
	  at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.mergeCloneWithReferences(UnitOfWorkImpl.java:3440)
	  at org.eclipse.persistence.internal.jpa.EntityManagerImpl.mergeInternal(EntityManagerImpl.java:414)
	  at org.eclipse.persistence.internal.jpa.EntityManagerImpl.merge(EntityManagerImpl.java:391)
	  at com.sun.enterprise.util.EntityManagerWrapper.merge(EntityManagerWrapper.java:476)
	  at xxx.BaseManager.save(BaseManager.java:69)
	  at xxx.DocumentManager.saveExisting(DocumentManager.java:398)
	  at xxx.DocumentManager.save(DocumentManager.java:265)
	  at xxx.DocumentManager.moveToList(DocumentManager.java:211)
	  at sun.reflect.GeneratedMethodAccessor8012.invoke(Unknown Source:-1)
	  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	  at java.lang.reflect.Method.invoke(Method.java:597)
	  at com.sun.enterprise.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1011)
	  at com.sun.enterprise.security.SecurityUtil.invoke(SecurityUtil.java:175)
	  at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:4030)
	  at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:483)
	  at com.sun.ejb.Invocation.proceed(Invocation.java:498)
	  at xxx.ClientInterceptor.intercept(ClientInterceptor.java:38)
	  at sun.reflect.GeneratedMethodAccessor7327.invoke(Unknown Source:-1)
	  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	  at java.lang.reflect.Method.invoke(Method.java:597)
	  at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:579)
	  at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:483)
	  at com.sun.ejb.Invocation.proceed(Invocation.java:498)
	  at xxx.SaveInterceptor.intercept(SaveInterceptor.java:36)
	  at sun.reflect.GeneratedMethodAccessor7326.invoke(Unknown Source:-1)
	  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	  at java.lang.reflect.Method.invoke(Method.java:597)
	  at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:579)
	  at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:483)
	  at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:205)
	  at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4003)
	  at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:197)
	  at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:127)
	  at $Proxy733.moveToList(Unknown Source:-1)
	  at xxx.ApplicationList.move(ApplicationList.java:562)
	  at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java:-1)
	  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	  at java.lang.reflect.Method.invoke(Method.java:597)
	  at com.sun.el.parser.AstValue.invoke(AstValue.java:187)
	  at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
	  at xxx.MethodExpressionDecorator.invoke(MethodExpressionDecorator.java:24)
	  at xxx.SecureMethodExpression.invoke(SecureMethodExpression.java:30)
	  at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
	  at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
	  at xxx.ActionListenerImpl.processAction(ActionListenerImpl.java:99)
	  at javax.faces.component.UICommand.broadcast(UICommand.java:387)
	  at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:475)
	  at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:756)
	  at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:82)
	  at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
	  at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
	  at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
	  at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:427)
	  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:333)
	  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
	  at xxx.ExtensionsFilter.doFilter(ExtensionsFilter.java:108)
	  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:246)
	  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)
	  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:313)
	  at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:287)
	  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:218)
	  at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
	  at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
	  at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:94)
	  at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:98)
	  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:222)
	  at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
	  at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
	  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
	  at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
	  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:166)
	  at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:648)
	  at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:593)
	  at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:587)
	  at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:1096)
	  at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:288)
	  at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.invokeAdapter(DefaultProcessorTask.java:647)
	  at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.doProcess(DefaultProcessorTask.java:579)
	  at com.sun.enterprise.web.connector.grizzly.DefaultProcessorTask.process(DefaultProcessorTask.java:831)
	  at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.executeProcessorTask(DefaultReadTask.java:341)
	  at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:263)
	  at com.sun.enterprise.web.connector.grizzly.DefaultReadTask.doTask(DefaultReadTask.java:214)
	  at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:265)
	  at com.sun.enterprise.web.connector.grizzly.ssl.SSLWorkerThread.run(SSLWorkerThread.java:106)


Re: Merge resets new data [message #550900 is a reply to message #550392] Wed, 04 August 2010 15:21 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1039
Registered: July 2009
Senior Member
Hello,

Problem seems to be that the application is some how causing the refresh of the managed User entity - either directly through a em.refresh or a query using the refresh hint, on it or any entity referencing it with the cascade refresh set. This causes the managed User entity to have an untriggered lazily fetched Documents list, that when fetched will cause the referenced Documents to also be refreshed.

The merge to Documents is successful and then cascades to User. As this occurs, the Detached User's list of Documents needs to be compared to the managed User's untriggered Document list, causing it to be triggered. This causes a refresh query to be executed, overwriting the changes merged in so far.

So removing the cascading refresh on the User->Document will resolve this issue, but in general, cascade refresh may have unintended consequences on lazy relationships. Had the User->Document relationship not been fetched on the detached User being merged, this problem could occur later if the application accessed the relationship after the merge.

Best Regards,
Chris
Re: Merge resets new data [message #550910 is a reply to message #550900] Wed, 04 August 2010 15:44 Go to previous message
Alex Ka is currently offline Alex KaFriend
Messages: 4
Registered: July 2010
Location: Sofia, Bulgaria
Junior Member
Hi,

I removed the cascade refresh and it seems ok now. Thanks for the comment Chris Smile

I was wondering, if EclipseLink had some more logic into the refreshing of the lazy relationship, wouldn't it be possible to merge/refresh without creating this problem. After all the developer wants to merge a modified Entity and because of the refreshing of a lazy relationship that the same Entity is found in, the merged data gets overwritten. Of course, it's possible that my question/example is incorrect in first place, but... Rolling Eyes

Kind regards,
Alex
Previous Topic:Attribute.isAssociation in metamodel API returns false for relationship mappings
Next Topic:setMaxResults() doesn't work with MySql - sql syntax error
Goto Forum:
  


Current Time: Sun Nov 23 07:45:15 GMT 2014

Powered by FUDForum. Page generated in 0.01698 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software