-->
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.  [ 7 posts ] 
Author Message
 Post subject: saveOrUpdate to database
PostPosted: Sun May 16, 2004 6:37 am 
Beginner
Beginner

Joined: Tue May 11, 2004 10:40 am
Posts: 37
Location: Belgium
Here I'm back with the same question:

I have the following situation:

c1 has 2 children c2 and c3

c2 has also 2 children c4 and c5.

when I store c1 into the database, everything works fine.
when I load c1 back from the database, remove c4 and store
c1 into the database again, c4 is not removed from the database.

Hibernates does not reconize the changes made in the tree.

.......................................
.................c4...................
.............../.......................
.........c2--........................
....... / .....\......................
..c1--..........c5..................
........\ .............................
.........c3...........................
.......................................

How can I solve that problem?

For the connection to the database I use following code:
Code:
       Session session = sessions.openSession();
        Transaction tx = null;
        try {
            tx = session.beginTransaction();
            session.saveOrUpdate(comp);
            tx.commit();
        }
        catch (HibernateException he) {
            if (tx!=null) tx.rollback();
            throw he;
        }
        finally {
            session.close();
        }

Because I use saveOrUpdate, you should think hibernate would update the database. Well, he doesn't.

Am I missing something. I did not paste any code because I think this is a very general question.

Is it a cache concern, or something else?



Thanks in advance,
Stijn.


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 16, 2004 6:54 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Do you have cascade="all-delete-orphan" set?


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 16, 2004 7:03 am 
Beginner
Beginner

Joined: Tue May 11, 2004 10:40 am
Posts: 37
Location: Belgium
It seems hibernate does not know that feature:
Code:
Attribute "cascade" with value "all-delete-orphan" must have a value from the list "none all save-update delete "


When I set it to 'all' or 'save-update' hibernate sais "stackoverflow"

For completeness: here's my mapping code:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
   
    <class
        name="logic.framework.Component"
        table="COMPONENT">
       
        <id
            name="id"
            column="ID"
            type="java.lang.Long"
            unsaved-value="null">         
            <generator class="foreign">
                <param name="property">price</param>
            </generator>
        </id>
       
        <discriminator
            column="DISCRIMINATOR"
            type="string"/>             

        <property
            name="name"
            column="NAME"
            not-null="false"
            unique="false"
            type="java.lang.String"/>
           
        <property
            name="description"
            column="DESCRIPTION"
            not-null="false"
            unique="false"
            type="java.lang.String"/>
           
        <property
            name="extension1"
            column="EXTENSION1"
            not-null="false"
            unique="false"
            type="java.lang.String"/>

        <property
            name="extension2"
            column="EXTENSION2"
            not-null="false"
            unique="false"
            type="java.lang.String"/>
           
        <property
            name="photo"
            column="PHOTO"
            not-null="false"
            unique="false"
            type="blob"/>
                       
        <bag
            name="children"
            inverse="true"
            lazy="false"
            cascade="all-delete-orphan">           
            <key column="PARENT"/>
            <one-to-many class="logic.framework.Component"/>
        </bag>

        <bag
            name="excludedComponents"
            table="EXCL_COMP"
     
            lazy="false"
            cascade="all-delete-orphan">           
            <key column="ID"/>
            <many-to-many column="excl_comp" class="logic.framework.Component"/>
        </bag>
           
        <one-to-one name="price" class="logic.framework.Currency"/> 
                           
        <many-to-one
            name="parent"
            column="PARENT"
            not-null="false"
            cascade="all-delete-orphan"
            class="logic.framework.Component"/> 
           
        <subclass
            name="logic.framework.CompositeComponent"
            discriminator-value="compositeComponent"/>

       
        <subclass
            name="logic.framework.Leaf"
            discriminator-value="leaf"/>
           
        <subclass
            name="logic.Item"
            discriminator-value="item"/>           
           
        <subclass
            name="logic.framework.LinkComposite"
            discriminator-value="linkComposite"/>
           
        <subclass
            name="logic.framework.StdComposite"
            discriminator-value="stdComposite"/>                       

        <subclass
            name="logic.Model"
            discriminator-value="model"/>
           
        <subclass
            name="logic.framework.RootComposite"
            discriminator-value="rootComposite"/>
           
        <subclass
            name="logic.ItemComposite"
            discriminator-value="itemComposite"/>   
           
        <subclass
            name="logic.ConfigObject"
            discriminator-value="configObject"/>                                                   
    </class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 16, 2004 7:34 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Are you using a recent hibernate version?


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 16, 2004 7:40 am 
Beginner
Beginner

Joined: Tue May 11, 2004 10:40 am
Posts: 37
Location: Belgium
Yes, version 2.1.3

My fault was in the <many-to-one> property, where cascade has to be 'save-update'.

But now, the following error occured:
Code:
You may not dereference a collection with cascade="all-delete-orphan"

What does it mean?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 02, 2004 3:12 am 
Newbie

Joined: Thu Sep 25, 2003 7:47 am
Posts: 4
Location: Japan
seems a late reply,

but i think that's because you set the whole collection null, but not only remove a child from the collection

Hope it can help.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 03, 2004 9:11 am 
Beginner
Beginner

Joined: Tue May 11, 2004 10:40 am
Posts: 37
Location: Belgium
Tele wrote:
seems a late reply,

but i think that's because you set the whole collection null, but not only remove a child from the collection

Hope it can help.


It's allready solved. Thanks anyway...
Greetz, Stijn.


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

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.