-->
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.  [ 9 posts ] 
Author Message
 Post subject: Problem with Cascade=all and save & update
PostPosted: Mon Dec 01, 2003 2:44 pm 
Regular
Regular

Joined: Thu Nov 20, 2003 10:44 am
Posts: 58
Location: Paris, France
Dear all,
I have the following problem :

-> I have a class, FormulaireAdhesionPersistent, which contains a tab of DemandeAdhesionValeur.
-> The key of DemandeAdhesionPersistent is generated with a sequence

When I update FormulaireAdhesionPersistent, hibernate create new instance for each elements of the tab of DemandeAdhesionPersistentinstead of updating it !!!

Java as follows :
Code:
public class FormulaireAdhesionPersistent
      implements Serializable
{
  private String numFormulaireAdhesion ; // key
...
...
   private DemandeAdhesionPersistent listeDemandeAdhesion[] ;
...
...
}

public class DemandeAdhesionPersistent
{
   private int numDemandeAdhesion ; // key
...
...
   private FormulaireAdhesionPersistent formulaireAdhesion ;
...
...
}


Mapping as follows :
Code:
<hibernate-mapping>
   <class name="FormulaireAdhesionPersistent" table="FORMULAIRE_ADHESION">
      <id name="numFormulaireAdhesion" column="PK_FORMULAIRE_ADHESION">
         <generator class="assigned"/>
      </id>
...
...
      <set name="listeDemandeAdhesion" lazy="true" inverse="true">
         <key column="FK_NUM_FORMULAIRE"/>
         <one-to-many class="DemandeAdhesionPersistent"/>
      </set>
...
...
   </class>
</hibernate-mapping>

<hibernate-mapping>
   <class name="fr.gouv.finances.dgi.opale.commun.transverse.persistent.DemandeAdhesionPersistent" table="DEMANDE_ADHESION">
      <id name="numDemandeAdhesion" column="PK_DEMANDE_ADHESION" type="int" unsaved-value="any">
         <generator class="sequence">
            <param name="sequence">S_DEMANDE_ADHESION</param>
         </generator>
      </id>
...
...
      <many-to-one name="formulaireAdhesion" column="FK_NUM_FORMULAIRE" cascade="none" class="FormulaireAdhesionPersistent" not-null="true"/>
...
...

   </class>
</hibernate-mapping>


Thanks for your help[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 01, 2003 3:15 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Of course, you ask for it ;-)

Code:
<id name="numDemandeAdhesion" column="PK_DEMANDE_ADHESION" type="int" unsaved-value="any">


unsaved-value="any" means that for any id, hibernate will save (insert it)

either used unsaved-value="null" or unsaved-value="0" wether you use primary type for id or not.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 01, 2003 3:49 pm 
Regular
Regular

Joined: Thu Nov 20, 2003 10:44 am
Posts: 58
Location: Paris, France
Unfortunatly it doesn't work .. I put :
unsaved-value="0"
as the id is an int, but but ... it is not ok !


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 01, 2003 7:10 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hum, since you're using array the <array> mapping is more appropriate (required).
But it needs to have a index column (section 6.2).

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 02, 2003 4:36 am 
Regular
Regular

Joined: Thu Nov 20, 2003 10:44 am
Posts: 58
Location: Paris, France
Sorry for the copy/paste but I use a set of collection and not an array !

I really don't understand what's happen and why Hibernate triggers the sequence to create the list of DemandeAdhesionPersistent !!!

grrr...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 02, 2003 4:46 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
How about you start again, taking the example in the "eg" directory of the Hibernate 2.1 distribution as your starting point, and change it until it looks more like you model, and see when it breaks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 02, 2003 9:03 am 
Regular
Regular

Joined: Thu Nov 20, 2003 10:44 am
Posts: 58
Location: Paris, France
Actually unsaved-value="save-update" wprks ...

Thanks for your help


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 02, 2003 9:57 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
gbonnard wrote:
Actually unsaved-value="save-update" wprks ...


?? unsaved-value cannot be "save-update" only cascade can.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 02, 2003 1:20 pm 
Regular
Regular

Joined: Thu Nov 20, 2003 10:44 am
Posts: 58
Location: Paris, France
Yes sorry it is this attribute


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