-->
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: hibernate saveOrUpdate doesn't save new obj with assigned id
PostPosted: Thu Jan 08, 2009 1:13 pm 
Newbie

Joined: Wed Jul 18, 2007 3:09 pm
Posts: 4
Question is when an object with an assigned id was created and saved using org.springframework.orm.hibernate3.support.HibernateDaoSupport.getHibernateTemplate().saveOrUpdate(obj),
saveOrUpdate did update() instead of save(). why hibernate didn't know it is a new object and do save() ?


Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0

Mapping documents:
Code:
<hibernate-mapping package="com.amg.brides.wedsimple.account.model">
    <class name="com.amg.brides.wedsimple.account.model.WedSimpleAccountSync" table="wedsimple_sync_acct">
          <cache usage="nonstrict-read-write" />

    <id name="id" column="user_id" type="long" unsaved-value="0" />
    <property name="sync" column="sync" type="string" not-null="false" />
    </class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Code:
org.springframework.orm.hibernate3.support.HibernateDaoSupport.getHibernateTemplate().saveOrUpdate(obj);

Full stack trace of any exception that occurs:
no error but no data is saved. When saveOrUpdate(new Object()) is called, hibernate did update by issuing a update statement. It should be calling save() with an insert sql.
Name and version of the database you are using:
Oracle 10g
The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:
When saveOrUpdate(new Object()) is called, hibernate did update by issuing a update statement. It should be calling save() with an insert sql.

Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2009 2:49 pm 
Newbie

Joined: Wed Jul 18, 2007 3:09 pm
Posts: 4
I think the answer might be this:

hibernate uses <unsaved-value> to determine if data is new (save) or old(update). when a new object is created with assigned id like 122, which is not specified unsaved-value, it thinks obj is old then do update.

If this is wrong, please let me know


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 09, 2009 12:12 am 
Regular
Regular

Joined: Wed Oct 15, 2008 6:59 am
Posts: 103
Location: Chennai
yes friend hibernate use this configuration as u said...

take a view this post ...

http://forum.hibernate.org/viewtopic.php?t=993431

_________________
If u feel it will help you, don't forget to rate me....


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.