[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-1914) session.merge(persistentEntity) fails on unmodifiable collections

Pedro Teixeira (JIRA) noreply at atlassian.com
Thu Dec 17 10:30:29 EST 2009


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1914?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=34973#action_34973 ] 

Pedro Teixeira commented on HHH-1914:
-------------------------------------

Actually, the problem I'm seeing (3.3.2.GA) is that, somehow, copyValues is not copying the a set when merging. 


It is probably not related to unmodifiable set.

> session.merge(persistentEntity) fails on unmodifiable collections
> -----------------------------------------------------------------
>
>                 Key: HHH-1914
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1914
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: core
>            Reporter: Emmanuel Bernard
>            Priority: Minor
>
> 		Cat cat = new Cat();
> 		cat.setId( new CatPk() );
> 		cat.getId().setName( "titi" );
> 		cat.getId().setThoroughbred( "unknown" );
> 		Set<Woman> women = new HashSet<Woman>();
> 		Woman woman = new Woman();
> 		woman.setId( new WomanPk() );
> 		woman.getId().setFirstName( "Lady" );
> 		woman.getId().setLastName( "McBeth" );
> 		women.add( woman );
> 		cat.setHumanContacts( Collections.unmodifiableSet( women ) );
> 		Set<Cat> cats = new HashSet<Cat>();
> 		cats.add( cat );
> 		woman.setCats( Collections.unmodifiableSet(cats) );
> 		s.persist( cat );
> 		s.persist( woman );
> 		tx.commit();
> 		s.merge( woman );
> During merge, the entity is copied into itself (?)
> defaultmergeeventlistener.entityIsPersistent() => copyValues(persister, entity, entity, source, copyCache);
> java.lang.UnsupportedOperationException
> 	at java.util.Collections$UnmodifiableCollection.clear(Collections.java:1037)
> 	at org.hibernate.collection.PersistentSet.clear(PersistentSet.java:247)
> 	at org.hibernate.type.CollectionType.replaceElements(CollectionType.java:404)
> 	at org.hibernate.type.CollectionType.replace(CollectionType.java:449)
> 	at org.hibernate.type.TypeFactory.replace(TypeFactory.java:437)
> 	at org.hibernate.event.def.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:282)
> 	at org.hibernate.event.def.DefaultMergeEventListener.entityIsPersistent(DefaultMergeEventListener.java:132)
> 	at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:105)
> 	at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:51)
> 	at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:677)
> 	at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:661)
> 	at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:665)
> 	at org.hibernate.test.annotations.manytomany.ManyToManyTest.testUnmodifiableCollection(ManyToManyTest.java:102)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at org.hibernate.test.annotations.TestCase.runTest(TestCase.java:67)
> 	at com.intellij.rt.execution.junit2.JUnitStarter.main(JUnitStarter.java:32)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> 	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
> What is the reason for that? The spec says that 
> "If X is a managed entity, it is ignored by the merge operation"

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


More information about the hibernate-issues mailing list