-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: All delete orphan for an object entity-name in component
PostPosted: Mon Jul 17, 2006 1:35 pm 
Newbie

Joined: Mon Jul 17, 2006 12:53 pm
Posts: 5
My problem is that the deletion of all orphan for a collection (set) in a component is not possible if I set the object mapped with component to null. The only solution that I found in order to uptade correctly the database is to set all values of the object (including the collection) to null.

I have the following mapping:
Code:
...
<key column="key1" />
<component name="serialNumber" class="SerialNumber">
        <parent name="parent" />
        <property name="value1" column="Value1" />
        <set name="otherValues" cascade="all-delete-orphan" inverse="true" >
                <key column="key1" not-null="true" />
                <one-to-many entity-name="OtherValues" />
        </set>
</component>

<class entity-name="OtherValues" name="OtherValue" table="OtherValue">
         ...
         <property name="value" column="otherValue" type="string" />
         <many-to-one name="parent" class="Serial" column="key1" not-null="true" />
</class>
...

The pojos are the following:
Code:
public class MyClass{
       ...
       private SerialNumber serialNumber;
       ...

       public void setSerialNumber(final SerialNumber serialNumber) {
                    if (this.serialNumber != null && serialNumber == null) {
                           // this.serialNumber.setParent(this);
                            this.serialNumber = null;
                    }
                    if (serialNumber != null) {
                           this.serialNumber = serialNumber;
                           this.serialNumber.setParent(this);
                   }
       }

}

public class SerialNumber{
        private String value1;
        private Object parent;
        private Set<OtherValue> otherValues;

        public void setParent(final Object parent) {
                   if (parent == null) {
                           this.value1= null;
                           this.otherValues.clear();
                           this.parent = null;
                   } else {
                           this.parent = parent;
                           for (final OtherValue oneOtherValue: this.otherValues) {
                                 oneOtherValue.setParent(parent);
                           }
                   }
         }
}


If in my code I do MyClass.setSerialNumber(null) with the code "this.serialNumber = null;" in the function "setSerialNumber" and I save, I have the following error:org.hibernate.HibernateException: A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance: otherValues.

If in my code I do MyClass.setSerialNumber(null) with the code this.serialNumber.setParent(this); in the function "setSerialNumber" and I save, I haven't error and the object is correctly saved in the database but in the session hibernate the object SerialNumber is not null but have all his attributes equal as null.

I would like to find a solution to set the object SerialNumber to null.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.