-->
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.  [ 5 posts ] 
Author Message
 Post subject: Problem with saveOrUpdate/Interceptor: migration to 3.05
PostPosted: Wed Aug 31, 2005 9:16 pm 
Newbie

Joined: Thu May 26, 2005 6:31 pm
Posts: 19
3.05:

I am trying to migrate our application from hibernate2 to 3.05. Went through quite a few problems. I am almost there untill met this problem. Basically, the saveOrUpdate function is not working for whatever reason. When I tries to insert an object with null ID using saveOrUpdate, saveOrUpdate tries to do an update and of course fails.

The same code is working before. Any idea what may goes wrong? We are using mysql. The id column is auto increment and the mapping of id is using native generator.

The only thing I can think about is the new change with Interceptor. We do implement the Interceptor and do some cool stuff. There are a bunch of new abstract methods added to the interface. One of them is isTransient(Object). I do not know the use of this method and whether or not I have to implement it. For know, I always return false. Maybe that's the reason hibernate tries to update the object instead of insert it.

Full stack trace of any exception that occurs:
Aug 2005 17:31:07,692-HibernateServiceBase:ERROR:http-8080-Processor5] Unable to store Object.
org.hibernate.TransientObjectException: The given object has a null identifier: com.foo.bo.Login
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.getUpdateId(DefaultSaveOrUpdateEventListener.java:225)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsDetached(DefaultSaveOrUpdateEventListener.java:212)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:91)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:468)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:463)


Name and version of the database you are using: MySQL 4.1.12[quote][/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 9:19 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Read the Javadoc.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 9:25 pm 
Newbie

Joined: Thu May 26, 2005 6:31 pm
Posts: 19
gavin wrote:
Read the Javadoc.

Which part of the javadoc? The interceptor?

public Boolean isTransient(Object entity)

Called to distinguish between transient and detached entities. The return value determines the state of the entity with respect to the current session.

* Boolean.TRUE - the entity is transient
* Boolean.FALSE - the entity is detached
* null - Hibernate uses the unsaved-value mapping and other heuristics to determine if the object is unsaved

Parameters:
entity - a transient or detached entity
Returns:
Boolean or null to choose default behaviour


I don't know whether or not it has something to do with the Interceptor. Same code which is working before and not working after the migration. Nothing has been mentioned about this in the migration guide.

thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 9:31 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
So, did you try returning null?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 31, 2005 9:51 pm 
Newbie

Joined: Thu May 26, 2005 6:31 pm
Posts: 19
Thanks. It is the problem. Now, it's all working.


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