-->
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.  [ 4 posts ] 
Author Message
 Post subject: I do a save(), but hibernate attempts to do an Update
PostPosted: Fri Oct 22, 2004 9:26 am 
Newbie

Joined: Mon Oct 04, 2004 7:13 am
Posts: 19
I do a save(), but hibernate attempts to do an Update.
Therefore I get:

net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25)


Here's the beginning of the HBM:

<class name="MasterHibernate" table="RMASTER" >

<id name="masterID" unsaved-value="null" type="com.lbss.framework.hibernate.domain.types.IntegerMapper">
<column name="RMSFILENUM" not-null="true"/>
<generator class="assigned"/>
</id>


And here's the simple code:
MasterHibernate pojo = new MasterHibernate();
pojo.setMasterID(new Integer(199));
pojo.setBlockPayment(LBSSBoolean.FALSE);
session.save(pojo);


I've tried unsaved-value=any but it gives the same problem. I must be missing something obvious here, but I've been through the faqs and docs and can't see what I'm doing wrong.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 22, 2004 12:11 pm 
Beginner
Beginner

Joined: Tue Sep 21, 2004 4:04 pm
Posts: 25
Location: Oldsmar, FL
I'm pretty new to Hibernate but from what I've read, the unsaved-value doesn't make sense on an assigned identifier.
Because it's assigned there will never be a value that indicates it's unsaved.

If you use an assigned identifier then you need to provide a version property or a timestamp with an unsaved-value.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 22, 2004 12:29 pm 
Newbie

Joined: Mon Oct 04, 2004 7:13 am
Posts: 19
Problem solved. But no idea why.

If I'm issuing a session.save(entity), surely Hibernate should do an insert.

I've actually tracked this down to the deepCopy() method on a custom type that i had on my entity. I have to return the object instead of a copy and it all works fine:


public Object deepCopy(Object x) {
return x;
//return new LBSSCurrency(((LBSSCurrency)x).getValue());
}


But why on earth this has fixed the problem I have no idea.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 24, 2004 10:17 am 
Regular
Regular

Joined: Mon Nov 24, 2003 6:36 pm
Posts: 105
Just an fyi, hib does not necessarily do an insert when sess.save is called.

If your id is assigned, then a timestamp column/property can be used, of some other prop for "unsaved value"

James


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