-->
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: API to check if entity is new
PostPosted: Fri May 07, 2004 9:10 am 
Newbie

Joined: Tue Apr 13, 2004 6:41 am
Posts: 19
Is there Metadata API/Helper to check if Entity is new (instance data meets unsaved-value criteria)?
Could not find anything like that in ClassMetadata...

Rihards


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 07, 2004 10:07 am 
Regular
Regular

Joined: Tue Jan 13, 2004 4:57 am
Posts: 83
This is what happens in SessionImpl.saveOrUpdate:

Code:
         Boolean isUnsaved = interceptor.isUnsaved(object);
         ClassPersister persister = getPersister(object);
         if (isUnsaved==null) {
            // use unsaved-value
            
            if ( persister.isUnsaved(object) ) {
               log.trace("saveOrUpdate() unsaved instance");
               save(obj);
            }
            else {
               Serializable id = persister.getIdentifier(object);
               if ( log.isTraceEnabled() ) log.trace("saveOrUpdate() previously saved instance with id: " + id);
               doUpdate(object, id, persister);
            }

         }
         else {
            if ( isUnsaved.booleanValue() ) {
               log.trace("saveOrUpdate() unsaved instance");
               save(obj);
            }
            else {
               log.trace("saveOrUpdate() previously saved instance");
               doUpdate( object, persister.getIdentifier(object), persister );
            }
         }


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 07, 2004 10:08 am 
Regular
Regular

Joined: Tue Jan 13, 2004 4:57 am
Posts: 83
immanuel wrote:
This is what happens in SessionImpl.saveOrUpdate:

Code:
         Boolean isUnsaved = interceptor.isUnsaved(object);
         ClassPersister persister = getPersister(object);
         if (isUnsaved==null) {
            // use unsaved-value
            
            if ( persister.isUnsaved(object) ) {
               log.trace("saveOrUpdate() unsaved instance");
               save(obj);
            }
            else {
               Serializable id = persister.getIdentifier(object);
               if ( log.isTraceEnabled() ) log.trace("saveOrUpdate() previously saved instance with id: " + id);
               doUpdate(object, id, persister);
            }

         }
         else {
            if ( isUnsaved.booleanValue() ) {
               log.trace("saveOrUpdate() unsaved instance");
               save(obj);
            }
            else {
               log.trace("saveOrUpdate() previously saved instance");
               doUpdate( object, persister.getIdentifier(object), persister );
            }
         }


So you basically should be able to use session.getPersister() and then persister.isUnsaved( object ), I think. Beware I'm not an expert...


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.