-->
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.  [ 3 posts ] 
Author Message
 Post subject: updating the database
PostPosted: Thu May 13, 2004 11:14 am 
Beginner
Beginner

Joined: Tue May 11, 2004 10:40 am
Posts: 37
Location: Belgium
Hello,
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?

Thanks in advance,
Stijn.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 13, 2004 11:18 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
When asking questions, give at least:
the Hibernate version
your mapping documents
the Java code between sessionFactory.openSession() and session.close()
the full stack trace of any exception that occurs
the name and version of the database you are using
a debug level Hibernate log excerpt is also appreciated


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 13, 2004 11:23 am 
Beginner
Beginner

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

Code:
   public void Store(Component comp) throws HibernateException {
        Session session = sessions.openSession();
        Transaction tx = null;
        try {
            tx = session.beginTransaction();
            session.saveOrUpdate(comp);
            session.flush();
            tx.commit();
        }
        catch (HibernateException he) {
            if (tx!=null) tx.rollback();
            throw he;
        }
        finally {
            session.close();
        }
   }   

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.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="true"
            type="java.lang.String"/>
           
        <property
            name="description"
            column="DESCRIPTION"
            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="save-update">           
            <key column="PARENT"/>
            <one-to-many class="logic.Component"/>
        </bag>
         
        <one-to-one name="price" class="logic.Currency"/> 
                           
        <many-to-one
            name="parent"
            column="PARENT"
            not-null="false"
            cascade="save-update"
            class="logic.Component"/>
           
        <subclass
            name="logic.CompositeComponent"
            discriminator-value="composite"/>

       
        <subclass
            name="logic.Item"
            discriminator-value="item"/>
           
        <subclass
            name="logic.StdComposite"
            discriminator-value="stdcomposite"/>
           
        <subclass
            name="logic.ModelComposite"
            discriminator-value="modelcomposite"/>                       
               
    </class>

</hibernate-mapping>


No exceptions occured.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.