test
by Steve Ebersole
test
17 years, 10 months
[Hibernate-JIRA] Commented: (HHH-1654) Cascade problem when bidir OneToMany overlaps with OneToOne
by Adrian Pillinger (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1654?page=c... ]
Adrian Pillinger commented on HHH-1654:
---------------------------------------
I have a similar issue. Bi-directional one-to-one relationship.
Parent side (Address.class)
@OneToOne(cascade=CascadeType.ALL)
@JoinColumn(name="ADDDTL_ID")
private AddressDetail addressDetail;
Child side (AddressDetail.class)
@OneToOne(mappedBy="addressDetail", optional=false, cascade=CascadeType.ALL)
private Address address;
When I
1. Look up a persisted Address instance from the database
2. Create a new AddressDetail instance
3. Set the address property of the new AddressDetail to the looked up Address
4. Call merge(AddressDetail)
In the database the Address table column ADDDTL_ID is null, not set to the ID of the new AddressDetail (which FYI has been persisted to the database correctly.)
If I remove optional=false from the annotation in AddressDetail it works correctly - but I really want to enfore the AddressDetail to always have an Address.
> Cascade problem when bidir OneToMany overlaps with OneToOne
> -----------------------------------------------------------
>
> Key: HHH-1654
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1654
> Project: Hibernate3
> Type: Bug
> Environment: JBoss 4.0.4RC1, any database
> Reporter: Jeff Schnitzer
> 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.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
17 years, 10 months
[Hibernate-JIRA] Updated: (HHH-1829) Allow join on any property using property-ref
by Maarten Winkels (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1829?page=all ]
Maarten Winkels updated HHH-1829:
---------------------------------
Attachment: HHH-1829-mwinkels.patch
This is my (intermediate) solution (see attachments).
I think the code is not very clean, but all tests are green (both mine (attached as separate files) and the original tests). The following are implemented and tested:
- Generate correct foreign keys
- Basic operations (save, update, insert, fetch)
- HQL statements
- Bulk operations
> Allow join on any property using property-ref
> ---------------------------------------------
>
> Key: HHH-1829
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1829
> Project: Hibernate3
> Type: New Feature
> Components: core
> Versions: 3.2.0 cr1, 3.2.0.cr2
> Reporter: Maarten Winkels
> Assignee: Steve Ebersole
> Fix For: 3.2.3
> Attachments: AbstractJoinTest.java, HHH-1829-mwinkels.patch, JoinNoPropertyRefTest.java, JoinPropertyRefTest.java, Person.hbm.xml, Person.java, PersonNoPropertyRef.hbm.xml, hhh-1829.patch
>
>
> Currently joining tables for one class (uing the <join...> tag) is only supported for the id property. The property-ref is allowed on the <key..> tag inside the <join..> tag, but this is ignored.
--
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
17 years, 10 months