-->
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.  [ 13 posts ] 
Author Message
 Post subject: Cascade="all" and aggregated class
PostPosted: Mon Dec 01, 2003 1:44 pm 
Beginner
Beginner

Joined: Thu Nov 13, 2003 9:27 am
Posts: 26
Location: France
Hi all

I've a problem with 2 classes :

My object Form has a set of Queries, and my object Query references its Form.

My pb is : My Queries and Form have been modified and I need to update them. When I update my Form, hibernate creates new Queries (due to the cascade='all' property and the sequence generator in Query I think).

But if I don't mention the cascade="all" and want to update my Form, hibernate doesn't update my Queries.

What should I do ?

Here is my mapping :

Code:
<hibernate-mapping>
   <class name="FormPersistent" table="FORM">
      <id name="numForm" column="PK_FORM">
         <generator class="assigned"/>
      </id>
      <set name="listeQuery" lazy="true" inverse="true" [color=red]cascade="all"[/color]>
         <key column="FK_NUM_FORM"/>
         <one-to-many class="QueryPersistent"/>
      </set>
   </class>
</hibernate-mapping>


Code:
<hibernate-mapping>
   <class name="QueryPersistent" table="QUERY">
      <id name="numDemandeAdhesion" column="PK_QUERY" type="int">
         <[color=red]generator class="sequence"[/color]>
            <param name="sequence">S_QUERY</param>
         </generator>
      </id>
      <many-to-one name="form" column="FK_NUM_FORM" cascade="none" class="FormPersistent" not-null="true"/>
   </class>
</hibernate-mapping>


Thx for ur help :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 01, 2003 1:51 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Most likely a problem with your unsaved-value mappings.

Try either specifying an unsaved-value mapping for your Queries, or use Integer instead of int as id type


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 01, 2003 1:58 pm 
Beginner
Beginner

Joined: Thu Nov 13, 2003 9:27 am
Posts: 26
Location: France
I knew someone would say so =)

Bue I've tried all solutions : any, null, id_value and none.
None seems to do the job :/

Another idea ?


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

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
unsaved-value="0" ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 01, 2003 2:24 pm 
Beginner
Beginner

Joined: Thu Nov 13, 2003 9:27 am
Posts: 26
Location: France
nop sorry, it doesn't work either and I don't understand why.

Hibernate runs my sequence to create a new Query whatever I give as unsaved-value....


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

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Which hibernate version do you use ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 01, 2003 4:40 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Whatever, unsaved-value is the parameter to play with. Check id values just before the saveOrUpdate to see what's wrong in your code.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 02, 2003 4:23 am 
Beginner
Beginner

Joined: Thu Nov 13, 2003 9:27 am
Posts: 26
Location: France
I use hibernate 2.1 b


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

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Look at the example in the "eg" directory of the Hibernate 2.1 distribution, take that as a starting point, and work from there.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 02, 2003 5:48 am 
Beginner
Beginner

Joined: Thu Nov 13, 2003 9:27 am
Posts: 26
Location: France
Thanx Gavin, I read this, and did exactly the same (even replace my set with bag !). There's no "unsaved-value" property thus I removed mine, and put a cascade="save-update"

Here is the debug I get : as you can see, hibernate runs the sequence, for the update and I can't understand why.
I have this "unsaved-value strategy ANY", which is not true !

Code:
...
10:36:03,406 DEBUG Cascades:317 - unsaved-value strategy NULL
10:36:03,406 DEBUG SessionImpl:1328 - saveOrUpdate() previously saved instance with id: 00000549877
10:36:03,406 DEBUG SessionImpl:1381 - updating [FormPersistent#00000549877]
10:36:03,406 DEBUG SessionImpl:1163 - collection dereferenced while transient [FormPersistent.listeQuery#00000549877]
10:36:03,406 DEBUG Cascades:400 - processing cascades for: FormPersistent
10:36:03,421 DEBUG Cascades:427 - cascading to collection: FormPersistent.listeQuery
10:36:03,421 DEBUG Cascades:112 - cascading to saveOrUpdate()
10:36:03,421 DEBUG Cascades:298 - unsaved-value strategy ANY
10:36:03,421 DEBUG SessionImpl:1323 - saveOrUpdate() unsaved instance
10:36:03,421 DEBUG BatcherImpl:194 - about to open: 0 open PreparedStatements, 0 open ResultSets
10:36:03,437 DEBUG BatcherImpl:228 - prepared statement get: select S_QUERY.nextval from dual
Hibernate: select S_QUERY.nextval from dual
10:36:03,437 DEBUG BatcherImpl:234 - preparing statement
10:36:03,437 DEBUG SequenceGenerator:80 - Sequence identifier generated: 67
10:36:03,437 DEBUG BatcherImpl:201 - done closing: 0 open PreparedStatements, 0 open ResultSets
10:36:03,437 DEBUG BatcherImpl:247 - closing statement
10:36:03,437 DEBUG SessionImpl:731 - saving [QueryPersistent#67]
10:36:03,437 DEBUG Cascades:400 - processing cascades for: QueryPersistent
...



Here is my java code
Code:
sessionHibernate.getSession().saveOrUpdate(formPersistent);


The same as the one in eg example.
I can't see where I did it wrong. I need helllllp :)
Thanx in advance


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 02, 2003 6:08 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Listen, I am really confused as to what is so difficult about this!

Clearly Hibernate is doing EXACTLY what you tell it to do here.

You specify unsaved-value="any", it creates new instances
You speciy unsaved-value="none", it updates them

All as per the documentation.

Then, you specify unsaved-value="whatever the value of a newly instantiated instance is", and it updates them unless they are, in fact, newly instantiated.

Really, this is much more quickly solved by you doing a bit of experimentation and looking through the MANY examples of this, than by asking here.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 02, 2003 6:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
P.S. I hope you are changing the unsaved-value strategy of the *right class*.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 02, 2003 6:25 am 
Beginner
Beginner

Joined: Thu Nov 13, 2003 9:27 am
Posts: 26
Location: France
Yes, I changed the "right" class...

Now It works thx...


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