]
Gail Badner resolved HHH-1654.
------------------------------
Resolution: Rejected
Assignee: Gail Badner
Cascade problem when bidir OneToMany overlaps with OneToOne
-----------------------------------------------------------
Key: HHH-1654
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1654
Project: Hibernate Core
Issue Type: Bug
Environment: JBoss 4.0.4RC1, any database
Reporter: Jeff Schnitzer
Assignee: Gail Badner
Attachments: ContainerTest6-DenseRelationships.zip
Given the following relationships:
Parent has N children (one-to-many)
Child has 1 parent (many-to-one, the bidir relationship)
Parent has 1 "default" child (one-to-one)
Hibernate is unable to persist this. The code I expect to work:
Parent p = new Parent();
p.setChildren(new HashSet<Child>());
Child ch = new Child(p);
p.getChildren().add(ch);
p.setDefaultChild(ch);
this.em.persist(p);
However, it's possible to make it work by relaxing the NOT NULL constraint on the
defaultChild relationship and rearranging the order of method calls:
Parent p = new Parent();
p.setChildren(new HashSet<Child>());
Child ch = new Child(p);
p.getChildren().add(ch);
this.em.persist(p);
p.setDefaultChild(ch);
Of course, Hibernate works fine the one-to-one relationship is eliminated.
Here is the exception produced by the first code sequence:
Caused by: org.hibernate.PropertyValueException: not-null property references a null or
transient value: test.Child.parent
at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
at
org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:265)
at
org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:167)
at
org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:101)
at
org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:131)
at
org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:87)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:633)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:625)
at org.hibernate.engine.CascadingAction$8.cascade(CascadingAction.java:202)
at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:213)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:157)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:108)
at org.hibernate.engine.Cascade.cascade(Cascade.java:248)
at
org.hibernate.event.def.AbstractSaveEventListener.cascadeBeforeSave(AbstractSaveEventListener.java:385)
at
org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:242)
at
org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:167)
at
org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:101)
at
org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:131)
at
org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:87)
at
org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:642)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:616)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:620)
at
org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:127)
at org.jboss.ejb3.entity.InjectedEntityManager.persist(InjectedEntityManager.java:141)
at test.GoBean.go(GoBean.java:30)
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 org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:109)
at
org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
... 41 more
A test case is attached.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: