-->
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.  [ 8 posts ] 
Author Message
 Post subject: unsaved-value="any"
PostPosted: Thu Mar 04, 2004 9:55 am 
Newbie

Joined: Fri Oct 17, 2003 5:09 am
Posts: 13
Location: Madrid, Espa
Hello all,
Is it a good decision put always
Code:
unsaved-value="any"
when
Code:
<generator class="assigned"/>
?

if i not set to any, saveOrUpdate not works with transiant objets.

thanks in advance,
C


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 05, 2004 4:45 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
usaved-value="any" means saveOrUpdate = save

_________________
Emmanuel


Top
 Profile  
 
 Post subject: generator class="assigned" ---> unsaved-value=&
PostPosted: Fri Mar 05, 2004 5:10 am 
Newbie

Joined: Fri Oct 17, 2003 5:09 am
Posts: 13
Location: Madrid, Espa
Ok, my doubt is if when generator class="assigned" then i have to set ALWAYS unsaved-value="any"???

For instance:

Code:
  <class name="Plugin" table="plugin">
    <id name="pluginId" column="plugin_id" type="long"
          unsaved-value="any">
      <generator class="assigned"/>
    </id>
    <set
        name="traducciones"
        lazy="true"
        inverse="true"
        cascade="all"
    >
      <key column="plugin_id"/>
       <one-to-many class="Traduccion"/>
    </set>
  </class>

  <class name="Traduccion" table="traduccion">
    <id name="traduccionId" column="traduccion_id" type="long"
          unsaved-value="any">
      <generator class="assigned"/>
    </id>
    <property name="ingles" type="string"/>
    <property name="castellano" type="string"/>
    <many-to-one name="plugin" column="plugin_id"
        class="Plugin" not-null="true"/>
  </class>


if i save (or saveOrupdate) a plugin then Hibernate don't knows if have to save (sql insert) or update (sql update) traduccion, because pk is not null (assigned).

then, generator class="assigned" implies unsaved-value="any"???

thanks,
C


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 05, 2004 5:17 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
unsaved-value is only considered on cascades and saveOrUpdate(), not on save() or update()


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 05, 2004 6:31 am 
Newbie

Joined: Wed Mar 03, 2004 10:19 am
Posts: 11
Location: Netherlands
As far as I can grab it, saveOrUpdate is useless when using assigned id's. Why does hibernate not do the following in saveOrUpdate:
- check if an object with the requested id is already loaded (it would be the object passed to saveOrUpdate),
- if not, check if the object exists in the database
- if still not found, do a save (insert), otherwise, do an update

Frido


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 05, 2004 9:06 am 
Regular
Regular

Joined: Mon Nov 24, 2003 6:36 pm
Posts: 105
If you have an assigned identifier, the simplest thing for hibernate to know whether to issue an update vs an insert, is to use a seperate field with a date as <timestamp>
or <version> element in your mapping. If you have a last_updated field or something like that in your java object.

Check out <version> <timestamp> in the docs.

I wouldn't want hibernate to have the overhead of checking the db first for every object in my collection that might be new/existing.

Of course, I like to avoid the use of assigned altogehter if possible!

James


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 05, 2004 11:06 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
fridoo wrote:
As far as I can grab it, saveOrUpdate is useless when using assigned id's. Why does hibernate not do the following in saveOrUpdate:
- check if an object with the requested id is already loaded (it would be the object passed to saveOrUpdate),
- if not, check if the object exists in the database
- if still not found, do a save (insert), otherwise, do an update

Frido

This is highly inefficient ! And business PK sucks generally.
But as James pointed out, the <version unsaved-value=""> is precious in such cases.

OT: I'm afraid, however that people using assigned id don't use optimistic locking either :(

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 05, 2004 11:08 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You can do whatever you like in Interceptor.isUnsaved() .... but don't go to the database, thats crazy!


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