Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » NPE merging @ManyToOne entity
NPE merging @ManyToOne entity [message #1273148] Wed, 19 March 2014 15:53 Go to next message
Risto Oikarinen is currently offline Risto OikarinenFriend
Messages: 2
Registered: March 2014
Junior Member
I'm working with two linked entities using EclipseLink 2.5.1:

public class PermissionGroup {

   public final static String	SITES  = "sites";
   @ManyToMany(fetch = FetchType.LAZY)
   private Set<Site> sites = new LinkedHashSet<Site>();

public class Site {

   public final static String	PERMISSION_GROUPS = "permissiongroup";
   @ManyToMany(fetch = FetchType.LAZY, mappedBy = PermissionGroup.SITES)
   private Set<PermissionGroup> permissiongroup = new LinkedHashSet<PermissionGroup>();

I am trying to merge some changes to PermissionGroup.sites like this:

				EntityManager em = getEntityManager();
				T entity = em.find(getEntityClassMetadata().getMappedClass(), entityId);
				if (entity != null) {
					// make sure we are working with the latest versions
					getEntityClassMetadata().setPropertyValue(entity, propertyName, propertyValue);
					// re-attach also referenced entities to the persistence
					// context
					entity = em.merge(entity);
					entityA[0] = detachEntity(entity);

This homever ends up in a NPE:

	at org.eclipse.persistence.internal.sessions.MergeManager.registerObjectForMergeCloneIntoWorkingCopy(
	at org.eclipse.persistence.internal.sessions.MergeManager.mergeChangesOfCloneIntoWorkingCopy(
	at org.eclipse.persistence.internal.sessions.MergeManager.mergeChanges(
	at org.eclipse.persistence.mappings.CollectionMapping.mergeIntoObject(
	at org.eclipse.persistence.internal.descriptors.ObjectBuilder.mergeIntoObject(
	at org.eclipse.persistence.internal.sessions.MergeManager.mergeChangesOfCloneIntoWorkingCopy(
	at org.eclipse.persistence.internal.sessions.MergeManager.mergeChanges(
	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.mergeCloneWithReferences(
	at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.mergeCloneWithReferences(
	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.mergeCloneWithReferences(
	at org.eclipse.persistence.internal.jpa.EntityManagerImpl.mergeInternal(
	at org.eclipse.persistence.internal.jpa.EntityManagerImpl.merge(
	at com.vaadin.addon.jpacontainer.provider.MutableLocalEntityProvider.runInTransaction(
	at com.vaadin.addon.jpacontainer.JPAContainer.containerItemPropertyModified(
	at com.vaadin.addon.jpacontainer.JPAContainerItem$ItemProperty.setValue(
	at com.vaadin.ui.AbstractField.setValue(
	at com.vaadin.ui.AbstractSelect.setValue(
	at com.vaadin.ui.OptionGroup.setValue(
	at com.vaadin.ui.AbstractSelect.changeVariables(
	at com.vaadin.ui.OptionGroup.changeVariables(
	at com.vaadin.server.communication.ServerRpcHandler.changeVariables(
	at com.vaadin.server.communication.ServerRpcHandler.handleBurst(
	at com.vaadin.server.communication.ServerRpcHandler.handleRpc(
	at com.vaadin.server.communication.PushHandler$
	at com.vaadin.server.communication.PushHandler.callWithUi(
	at com.vaadin.server.communication.PushHandler.onRequest(
	at org.atmosphere.cpr.AsynchronousProcessor.action(
	at org.atmosphere.cpr.AsynchronousProcessor.suspended(
	at org.atmosphere.container.TomcatWebSocketUtil.doService(
	at org.atmosphere.container.Tomcat7AsyncSupportWithWebSocket.service(
	at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(
	at org.atmosphere.websocket.DefaultWebSocketProcessor.dispatch(
	at org.atmosphere.websocket.DefaultWebSocketProcessor$
	at org.atmosphere.util.VoidExecutorService.execute(
	at org.atmosphere.websocket.DefaultWebSocketProcessor.dispatch(
	at org.atmosphere.websocket.DefaultWebSocketProcessor.invokeWebSocketProtocol(
	at org.atmosphere.container.TomcatWebSocketHandler.onTextMessage(
	at org.apache.catalina.websocket.MessageInbound.onTextData(
	at org.apache.catalina.websocket.StreamInbound.doOnTextData(
	at org.apache.catalina.websocket.StreamInbound.onData(
	at org.apache.coyote.http11.upgrade.UpgradeProcessor.upgradeDispatch(
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(
	at java.util.concurrent.ThreadPoolExecutor.runWorker(
	at java.util.concurrent.ThreadPoolExecutor$

I am using EL through Vaadin framework and carefully checking for nulls before calling merge.

I browsed around, but didn't really find any useful resources... similar case has been discussed in this thread, but there was no conclusion to it.

Any points highly appreciated!


Risto Oikarinen

Re: NPE merging @ManyToOne entity [message #1274569 is a reply to message #1273148] Fri, 21 March 2014 16:54 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1342
Registered: July 2009
Senior Member
You should probably not be changing the collection out from the entity, and instead add or remove from the existing collection within the entity - changing the collection means change tracking cannot work. Try using the latest EclipseLink version, or try turning off change tracking bu setting persistence property "eclipselink.weaving.changetracking" to false.

I also don't think merge should be needed here, as the entity being merged is already apart of the context. The entities within the collection will not have merge cascaded to them anyway.
Re: NPE merging @ManyToOne entity [message #1276170 is a reply to message #1274569] Mon, 24 March 2014 07:22 Go to previous message
Risto Oikarinen is currently offline Risto OikarinenFriend
Messages: 2
Registered: March 2014
Junior Member
Hi Chris, and thanks for your reply!

I solved the problem. The Vaadin framework was incorrectly configured on this instance, trying to merge a wrong datatype (ie. not a collection, or LinkedHashSet in my case) into the @ManyToOne entity. The Vaadin-specific solution was to add a MultiSelectConverter to the Vaadin selector component, which then supplied proper Collection for merge.

I also tried "eclipselink.weaving.changetracking" as you suggested, but it didn't have effect here, since the problem was about supplied datatype and not the merge itself.
The currently working implementation is indeed replacing the whole collection in the @ManyToOne entity instead of adding/removing items. This is obviously non-optimal or might cause problems later on, but then I will have to live with it.


Risto Oikarinen
Previous Topic:Multi tenancy - NullPointerException
Next Topic:History for a OneToMany relationship not working
Goto Forum:

Current Time: Sat Apr 04 07:14:46 GMT 2020

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

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

Back to the top