-->
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.  [ 3 posts ] 
Author Message
 Post subject: Save or Update Query always updating
PostPosted: Fri Aug 20, 2004 4:26 am 
Beginner
Beginner

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

I have a DTIMER object which i am loading from a table, then i try to save it to another table in a new Database. the primary key(timer_id) will ALWAYS have a value in it, when i use saveOrUpdate it logically always trys to update the record as the unsaved-value is null

How would i tell it to save Or update the record in the new Table without having to null the primary key on the DTIMER object? if i use unsaved type="ANY' it will always insert and thats not what i want.

I cant find much information in the reference manual on the usage of unsaved-value="ID_VALUE" can anyone explain the usage of this?

Hibernate version: 2.1.3

Mapping documents:
<hibernate-mapping>
<class name="DTimer" table="d_timer">
<id name="timerID" column="id" type ="java.lang.Long" unsaved-value="null">
<generator class="native" />
</id>
<property name="trnID" column="trn_id" not-null="false"/>
<property name="dateTime" column="date_time" not-null="false"/>
<property name="suiteID" column="suitet_id" not-null="true"/>
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
DTimer s = (DTimer)it.next();
//s.setTimerID(null);
myMachineSession.saveOrUpdate(s);
myMachineSession.flush();
myMachineTX.commit();

Full stack trace of any exception that occurs:

Name and version of the database you are using:
MYSQL 3.2

Debug level Hibernate log excerpt:


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

Joined: Mon Aug 09, 2004 12:31 pm
Posts: 47
Location: New York, NY, USA
Wait, you didn't show the map to the second table.

Did you try generator="assigned" for the 2nd table? See http://www.hibernate.org/hib_docs/refer ... d-assigned

Actually the doc it says "...you have to explicitly specify to Hibernate if the object should be saved or updated by calling either the save() or update() method of the Session. " so I'm not sure if there's a one-line solution.. Probalby you will have to try loading it, and if it's there, do an update() otherwise a save(). But this might wreak havoc on the internal Hibernate object cache.

Maybe a more expert opinion is required...

_________________
--DP


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 21, 2004 4:37 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
If you must have assigned id's this post if for you http://forum.hibernate.org/viewtopic.php?t=933521,

else have a look at
http://forum.hibernate.org/viewtopic.php?t=933496.

HTH
Ernst

[/url]


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