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

Maxim Frolov (JIRA) noreply at atlassian.com
Tue Oct 26 08:19:48 EDT 2010


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

Maxim Frolov commented on HHH-1914:
-----------------------------------

The same issue with EclipseLink as Persistence Provider in validation context (using Hibernate as JSR303 validation provider):

I did the following:

@Entity           @Entity
RootEntity <----> LeafEntity
           1    *

RootEntity root = new RootEntity()
merge(root)
LeafEntity leaf = new LeafEntity()
leaf.setInvalidProperty()
leaf.setRoot(root)
root.addLeaf(leaf)
merge(leaf)
commit()

After commit() I have received in @PreSave-Listener a copy of root entity with empty collection of leafs (expected: non-empty collection) and validated that copy of root entity.
Validation has failed as expected but the ConstraintViolation was not correct: both RootBean und LeafBean were the same leaf entity (expected: root entity in RootBean, leaf entity in LeafBean).

> 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