-->
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.  [ 6 posts ] 
Author Message
 Post subject: usage of unsaved-value="ID_VALUE"?
PostPosted: Fri Aug 20, 2004 4:47 am 
Beginner
Beginner

Joined: Thu Aug 19, 2004 5:20 am
Posts: 25
Hi

Im looking for an explanation of unsaved-value="ID_VALUE", i cant find much info on it anywhere, could somebody please tell me its purpose and usage

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 20, 2004 6:55 pm 
Beginner
Beginner

Joined: Mon Aug 09, 2004 12:31 pm
Posts: 47
Location: New York, NY, USA
Hibernate uses the unsaved-value to detect if your object has been inserted yet or not. If the id of the object matches the unsaved value, it does an insert, otherwise an update. (There are lots of ways to modify this behavior.)

see http://www.hibernate.org/hib_docs/refer ... aration-id, where it says "(4) unsaved-value (optional - defaults to null): An identifier property value that indicates that an instance is newly instantiated (unsaved), distinguishing it from transient instances that were saved or loaded in a previous session. "

_________________
--DP


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 23, 2004 1:29 am 
Beginner
Beginner

Joined: Thu Aug 19, 2004 5:20 am
Posts: 25
Hi

I try to use unsaved-value="id_value" and it gives the error below? any ideas?

P.S the mapping is included below



Mapping spec from the manual
<id
name="propertyName" (1)
type="typename" (2)
column="column_name" (3)
unsaved-value="any|none|null|id_value" (4)
access="field|property|ClassName"> (5)

<generator class="generatorClass"/>
</id>
[i]

[B]ERROR[B]

net.sf.hibernate.MappingException: Could not parse unsaved-value: id_value
at net.sf.hibernate.persister.AbstractEntityPersister.<init>(AbstractEntityPersister.java:515)
at net.sf.hibernate.persister.EntityPersister.<init>(EntityPersister.java:623)
at net.sf.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:203)
at net.sf.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:594)
at HibernateDBConnection.initialiseSessions(HibernateDBConnection.java:44)
at HibernateDBConnection.getSession(HibernateDBConnection.java:66)
at XMLTest.getQuery(XMLTest.java:44)
at XMLTest.main(XMLTest.java:268)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)







[B]CODE AND MAPPING EXAMPLE[B]
<hibernate-mapping>
<!-- <class name="DTrns" table="d_trns" dynamic-update="true" select-before-update="true">-->
<class name="DTrns" table="d_trns" dynamic-update="true">
<id name="trnID" column="trn_id" type ="java.lang.Long" unsaved-value="id_value">
<generator class="native" />
</id>
<property name="workGroupBranchID" column="wkgrp_brch_id" not-null="true"/>
</class>
</hibernate-mapping>
[i]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 23, 2004 8:57 am 
Beginner
Beginner

Joined: Mon Aug 09, 2004 12:31 pm
Posts: 47
Location: New York, NY, USA
Replace the string "ID_VALUE" (no quotes) with the actual value of the identifier that means "never been inserted". Perhaps 0, or null, depending on the type of your identifier column/property.

_________________
--DP


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 23, 2004 8:58 am 
Beginner
Beginner

Joined: Mon Aug 09, 2004 12:31 pm
Posts: 47
Location: New York, NY, USA
(I meant "id_value" not "ID_VALUE")

_________________
--DP


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 23, 2004 9:13 am 
Beginner
Beginner

Joined: Thu Aug 19, 2004 5:20 am
Posts: 25
Thanks, worked a charm :)


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