-->
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.  [ 12 posts ] 
Author Message
 Post subject: update or delete ?
PostPosted: Tue Jan 20, 2004 4:52 am 
Regular
Regular

Joined: Thu Dec 25, 2003 12:33 am
Posts: 58
Location: Campina Grande, Brasil
I'm facing this problem...if i can delete, i can't update. if i can update, i can't delete.
I've mappe a one-to-many relationship this way:

Code:
<set name="lotes" inverse="true" cascade="delete">
            <key column="id_setor"/>
            <one-to-many class="beans.Lote"/>
        </set>


So i can delete items i need. I haven't explicitily defined a default-cascade in the top of the mapping file.
Well, the fact is , whith this configuration, i can't update items from beans.Lote.
If i remove the cascade="delete", so I can update.
How to be able to perform both?

Thanks

_________________
Ot


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2004 6:03 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
cascade="all"

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2004 6:08 am 
Regular
Regular

Joined: Thu Dec 25, 2003 12:33 am
Posts: 58
Location: Campina Grande, Brasil
You mean cascade="all" where ? in the default-cascade, at the beggining of the file?

Thanks

_________________
Ot


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2004 9:52 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Code:
<set name="lotes" inverse="true" cascade="all">
  <key column="id_setor"/>
  <one-to-many class="beans.Lote"/>
</set>

default-cascade is the value used when you don't explicitly override cascade value in collections.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2004 5:42 pm 
Regular
Regular

Joined: Thu Dec 25, 2003 12:33 am
Posts: 58
Location: Campina Grande, Brasil
Well,if I use cascade="all",and them try do session.delete in a child, it throws an HibernateException sayng i can'nt flush during deletion operation (that would be dangerous, etc...). Than, I could not use the cascade="all". In fact, it was cascade="all" in all my one to many relationships. When I started implementing the deletions requirements of my application, I got problems.

Thanks anyway, I'm going to try a new configuration with cascade="all"

_________________
Ot


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2004 9:40 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This is a FAQ man http://www.hibernate.org/117.html#A21

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 23, 2004 3:55 am 
Regular
Regular

Joined: Thu Dec 25, 2003 12:33 am
Posts: 58
Location: Campina Grande, Brasil
yeah, I could understand the fact that , before deleting, i must remove the deleted item from its parents. I've done it in one situation, and it worked fine. But in two others, it does not work.
The situation where it works is when I try to delete an object which has two parents, and no children. i remove it from its parents, and delete it after all. So, it is deleted ok.
The situation where it does not work is then i try to delete one of these two parents. Both are patents of the element i described above (the one I can delete). But one of them is parent of the other one. the cascade="all" mode is enabled, but i can't delete them. To remove the element which has a parent, i remove it from the parent's collection and them delete the element. to remove the element which is the parent of all, i just delete it.

If I did not make myself clear, please let me know. I can do everything whith hibernate in my system. Only the deletions are missing.

Thanks a lot for the atention

_________________
Ot


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 23, 2004 12:45 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Actually a simple code showing the case is way much simple.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 23, 2004 9:04 pm 
Regular
Regular

Joined: Thu Dec 25, 2003 12:33 am
Posts: 58
Location: Campina Grande, Brasil
this is the code where i try to remove a Setor object, which is the parent of all other objects

Code:
         SessionFactory sessionFactory =
            new Configuration().configure().buildSessionFactory();
         Session session;
         session = sessionFactory.openSession();
         Transaction trans = session.beginTransaction();

         Setor setor = (Setor) session.load(Setor.class, new Long(id));
         session.delete(setor);

         //request.getSession().setAttribute("apagasetor", set);
         session.flush();
         session.close();


The cascade="all" method is enabled. But stiil getting that message described some messges ago.

Thanks ;)

_________________
Ot


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 24, 2004 5:39 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
and now the mapping...

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 24, 2004 9:37 pm 
Regular
Regular

Joined: Thu Dec 25, 2003 12:33 am
Posts: 58
Location: Campina Grande, Brasil
this is the part that matters: the mapping for Setor and Lote
Setor is :
Code:
  <class name="beans.Setor" table="setores">
   
     <id name="id" column="id" type="java.lang.Long" unsaved-value="null" >
            <generator class="native"/>
        </id>
.
.
.
   <property name="livre">
            <column name="livre"   not-null="true"/>
        </property>
   <set name="lotes" inverse="true" cascade="all">
            <key column="id_setor"/>
            <one-to-many class="beans.Lote"/>
        </set>
   <set name="quadras" inverse="true" cascade="all">
            <key column="id_setor"/>
       <one-to-many class="beans.Quadra"/>
        </set>
</class>


Lote is:
Code:
<class name="beans.Lote" table="lotes">

     <id name="id" column="id" type="java.lang.Long" unsaved-value="null" >
            <generator class="native"/>
        </id>
.
.
.
<many-to-one name="setor" column="id_setor" />
   <many-to-one name="quadra" column="id_quadra"/>
</class>

So... any help ? :)

Thanks a lot

_________________
Ot


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2004 1:16 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
It's hard to understand that's your problem because it depends on:
- your full mapping (I see quadra references)
- data in your DB (especially the one explaining the grand-parent/parent/children part of your explaination)

the many-to-one tag has a cascade attribute, it may help to solve your problem

_________________
Emmanuel


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