-->
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.  [ 19 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: delete cascade bug (my code)
PostPosted: Tue May 18, 2004 4:18 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
hi all,
we're using hibernate 2.0 oracle 8i

mapping file:

Code:
<hibernate-mapping>
   <class name="com.auchan.balisage.bo.segmentation.Caracteristique" table="CARACTERISTIQUE">
      <id column="ID_CARACTERISTIQUE" name="idCaracteristique" >
         <generator class="sequence">
            <param name="sequence">SEQ_GROUPE_CARACTERISTIQUE</param>
         </generator>         
      </id>
      <property column="NOM"  name="nomCaracteristique" not-null="true" />
      <property column="VALEUR_DEFAUT"  name="valeurParDefaut" not-null="true" />
      <property column="ID_GROUPE"  name="idGroupe" not-null="true" />
      <property column="ID_NOMENCLATURE"  name="idNomenclature" not-null="true" />
      <property column="DATE_MODIFICATION"  name="dateModification" not-null="false" />
      <property column="ORDRE"  name="ordre" not-null="false" />
      <property column="OBLIGATOIRE"  name="obligatoire" not-null="false" />
      
      <many-to-one name="unite" column="ID_UNITE" />
      <many-to-one name="typeDonnees" column="ID_TYPE" />
             
       <bag name="valeurs" lazy="true" inverse="true" cascade="all" table="VALEUR_CARACTERISTIQUE">
         <key column="ID_CARACTERISTIQUE"/>
         <one-to-many column="ID_CARACTERISTIQUE" class="com.auchan.balisage.bo.segmentation.ValeurCaracteristique"/>
       </bag>
   </class>
</hibernate-mapping>


<hibernate-mapping>
   <class name="com.auchan.balisage.bo.segmentation.ValeurCaracteristique" table="VALEUR_CARACTERISTIQUE">
         <composite-id>
            <key-many-to-one name="produit" class="com.auchan.balisage.bo.produit.Produit" column="ID_PRODUIT"/>
            <key-many-to-one name="caracteristique" class="com.auchan.balisage.bo.segmentation.Caracteristique" column="ID_CARACTERISTIQUE"/>
       </composite-id>
       <property name="valeur" column="VALEUR" />
       <property name="valeurBlob" column="OBJECT" />
       <property name="dateCreation" column="DATE_CREATION" />
       <property name="dateModification" column="DATE_MODIFICATION" />
   </class>
</hibernate-mapping>



POJO CODE
Code:
public class ValeurCaracteristique implements Serializable{
   
   private Produit produit;
   private Caracteristique caracteristique;
   private Date dateCreation;
   private Date dateModification;
   private String valeur;
   private Blob valeurBlob;

   

 
   public boolean equals(Object other) {   
      if ( !(other instanceof ValeurCaracteristique) ) return false;
         ValeurCaracteristique castOther = (ValeurCaracteristique) other;       
      return new EqualsBuilder()   
      .append(this.getProduit().getIdProduit(), castOther.getProduit().getIdProduit())   
      .append(this.getCaracteristique().getIdCaracteristique(), castOther.getCaracteristique().getIdCaracteristique())           
      .isEquals();   
   }   
                             
   public int hashCode() {       
      return new HashCodeBuilder()           
      .append(getProduit().getIdProduit())           
      .append(getCaracteristique().getIdCaracteristique())                     
      .toHashCode();   
   }
   
   public String toString() {
        return new ToStringBuilder(this)
            .append("produit", getProduit().getIdProduit())
            .append("caracteristique", getCaracteristique().getIdCaracteristique())
            .toString();
    }

// get & set...


JAVA CODE
[code]
public void deleteObject(Integer idCaracteristique) throws DAOException{
try {
//R


Top
 Profile  
 
 Post subject: Ah auchan il faudrait d
PostPosted: Tue May 18, 2004 5:46 am 
Senior
Senior

Joined: Fri Nov 21, 2003 5:55 am
Posts: 155
Hello Anthony,

I have the same problem in my project but it's only for insert, the cascade delete works well.

Maybe you can implement a method remove in your POJO Caracteristique to start deleteting by the parent, I think it's better.
I hope it will help you.

public void removeCaracteristique(Produit produit) {
ValeurCaracteristique vcDAO = new ValeurCaracteristique ();
vcDAO.setCaracteristique(this);
vcDAO.setProduit(produit);
vcDAO.setDate(new Date());
......

valeurCaracteriqtiquesList.remove(vcDAO);
}

Maybe you have already solve your problem.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 5:57 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
thanks,
in fact i have found what is wrong, let me explain, hope i'll have a confirmation by advanced users.

I have
Caracteristique 1--* ValeurCaracteristique * -- 1 Produit


all the associations are bidirectionnal
I've set inverse=false and cascade = all in both Caracteristique & Produit mapping

I've a DAODelete methode for Produitin which i simply have
session.delete(myProd), this method works perfectly all ValeurCaracteristique childs are deleted.

I have the same method for Caracteristique in which i simply had session.delete(myCarac), and this method crash, with the exception give before.

I have to code this in order to do what i want
[code]
//R


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 8:32 am 
Senior
Senior

Joined: Fri Nov 21, 2003 5:55 am
Posts: 155
Why you put inverse to false?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 8:33 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
because i want ValeurCaracteristique to be responsible of the association maintenance not Product or Caracteristique


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 8:34 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
of course i wanted to say the contrary...
Product and Caracteristique will manage the association


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 8:47 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
excuse me, forget last two posts, i'm very busy,
the two bags are mapped with inverse="true"


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 9:26 am 
Senior
Senior

Joined: Fri Nov 21, 2003 5:55 am
Posts: 155
Ok no pb:)
Olivia said me you re busy.
Good luck


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 9:31 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Funny Olivia ;)

bonne journ


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 10:14 am 
Senior
Senior

Joined: Fri Nov 21, 2003 5:55 am
Posts: 155
J'ai juste une question, j'ai le m


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 10:14 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
In your last code fragment, which one succeed and which one fail?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 10:17 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
session.delete(myProduit) works fine with cascade...



session.delete(myCaracteristique), crash
i've to replace the line with
[code]//R


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 10:18 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
oh note that deleteObject() DAO method only call session.delete(obj) in the same session....


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 10:20 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hum, you have to since product is somehow loaded.
Are you sure you have a symetric cascade strategy/query between carac and product. Any more complex cycle between them (via thrid party entity

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 10:28 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
here are the 3 mapping files, as you can see, it seems very symetric

Code:
<hibernate-mapping>
<class name="com.auchan.balisage.bo.produit.Produit" table="PRODUIT">
<id column="ID_PRODUIT" name="idProduit" >
<generator class="sequence">
<param name="sequence">SEQ_PRODUIT</param>
</generator>
</id>
<property column="RIN" name="rin" not-null="true" />
<property column="LIBELLE" name="libelleProduit" not-null="true" />
<property column="LIBELLE_RPC" name="libelleRPC" not-null="false" />
<property column="PLUS_PRODUIT" name="plusProduit" not-null="true" />
<property column="DATE_CREATION" name="dateCreation" not-null="true" />
<property column="DATE_MODIFICATION" name="dateModification" not-null="true" />
<property column="ID_FAMILLE_RPC" name="idFamille" not-null="false" />
<property column="MISE_A_DISPOSITION" name="miseADisposition" not-null="false" />
<many-to-one column="ID_NOMENCLATURE" name="fiche" class="com.auchan.balisage.bo.segmentation.Nomenclature" not-null="false" />
<many-to-one name="marque" column="ID_MARQUE" />
<bag name="valeurs" lazy="true" inverse="true" cascade="all" table="VALEUR_CARACTERISTIQUE">
<key column="ID_PRODUIT"/>
<one-to-many column="ID_PRODUIT" class="com.auchan.balisage.bo.segmentation.ValeurCaracteristique"/>
</bag>
</class>

<hibernate-mapping>
   <class name="com.auchan.balisage.bo.segmentation.Caracteristique" table="CARACTERISTIQUE">
      <id column="ID_CARACTERISTIQUE" name="idCaracteristique" >
         <generator class="sequence">
            <param name="sequence">SEQ_GROUPE_CARACTERISTIQUE</param>
         </generator>         
      </id>
      <property column="NOM"  name="nomCaracteristique" not-null="true" />
      <property column="VALEUR_DEFAUT"  name="valeurParDefaut" not-null="true" />
      <property column="ID_GROUPE"  name="idGroupe" not-null="true" />
      <property column="ID_NOMENCLATURE"  name="idNomenclature" not-null="true" />
      <property column="DATE_MODIFICATION"  name="dateModification" not-null="false" />
      <property column="ORDRE"  name="ordre" not-null="false" />
      <property column="OBLIGATOIRE"  name="obligatoire" not-null="false" />
       
      <many-to-one name="unite" column="ID_UNITE" />
      <many-to-one name="typeDonnees" column="ID_TYPE" />
             
       <bag name="valeurs" lazy="true" inverse="true" cascade="all" table="VALEUR_CARACTERISTIQUE">
         <key column="ID_CARACTERISTIQUE"/>
         <one-to-many column="ID_CARACTERISTIQUE" class="com.auchan.balisage.bo.segmentation.ValeurCaracteristique"/>
       </bag>
   </class>
</hibernate-mapping>


<hibernate-mapping>
   <class name="com.auchan.balisage.bo.segmentation.ValeurCaracteristique" table="VALEUR_CARACTERISTIQUE">
         <composite-id>
            <key-many-to-one name="produit" class="com.auchan.balisage.bo.produit.Produit" column="ID_PRODUIT"/>
            <key-many-to-one name="caracteristique" class="com.auchan.balisage.bo.segmentation.Caracteristique" column="ID_CARACTERISTIQUE"/>
       </composite-id>
       <property name="valeur" column="VALEUR" />
       <property name="valeurBlob" column="OBJECT" />
       <property name="dateCreation" column="DATE_CREATION" />
       <property name="dateModification" column="DATE_MODIFICATION" />
   </class>
</hibernate-mapping>



in the javaCode, a simple session.delete should work but in one side it doesn't.

Can this be related to something specific to release 2.0?
Is it related to cascade or inverse ?
Does a bad equals() method can break the system?



Code:
   public boolean equals(Object other) {   
      if ( !(other instanceof ValeurCaracteristique) ) return false;
         ValeurCaracteristique castOther = (ValeurCaracteristique) other;       
      return new EqualsBuilder()   
      .append(this.getProduit().getIdProduit(), castOther.getProduit().getIdProduit())   
      .append(this.getCaracteristique().getIdCaracteristique(), castOther.getCaracteristique().getIdCaracteristique())           
      .isEquals();   
   }   
                             
   public int hashCode() {       
      return new HashCodeBuilder()           
      .append(getProduit().getIdProduit())           
      .append(getCaracteristique().getIdCaracteristique())                     
      .toHashCode();   
   }


I know the problem must be in my code but i've spend all the morning with the developper, modify some code but no way to get it work well.

In practice, all the process do is:
1- open session
2- load Caracteristique or Produit
3- delete it

this process works for Produit but for Caracteristique you see what i must do...

very strange ...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 19 posts ]  Go to page 1, 2  Next

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.