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: From 2.1.8 to 3.1
PostPosted: Wed Jun 29, 2005 6:13 am 
Beginner
Beginner

Joined: Wed Sep 17, 2003 10:43 am
Posts: 48
Hibernate version:
3.1a

I used to have the following in 2.1.8, but it's broken for 3.1, anyone has something similar? I cant even find how to get an EntityPersister (which looks like it should replace the Persister below). In sessionImplementor.getEntityPersister(string, object), what is the string attribute supposed to be? The documentation is rather poor.

/**
* Save the given object if new or update it if it has already been
* persisted (meaning if a record with the same identifier already
* exists).
*
* @param object the object to be saved or updated.
* @throws HibernateException
*/
public void saveOrUpdate(Object object) throws HibernateException {
boolean entityLoaded = false;
ClassPersister cp = ((SessionImplementor) this.session).getPersister(object);
Serializable id = cp.getIdentifier(object);
if(id != null && !"-1".equals(id.toString())){
Key objectKey = new Key(id, cp);
entityLoaded = ((SessionImplementor) this.session).getEntity(objectKey) != null;
// if the persisted version (an object with the same identifier)
// already exists in the session, update it using saveOrUpdateCopy
// (otherwise an exception will be thrown)
if (entityLoaded) {
log.debug("Saving transient object: "+object);
object = this.session.saveOrUpdateCopy(object);
}
// safe to use saveOrUpdate, no object with the same
// identifier exists in this session
else {
log.debug("Saving local object: "+object);
this.session.saveOrUpdate(object);
}
}else{
log.debug("Saving new object: "+object);
Serializable ids = this.session.save(object);
log.debug("Saved new object: "+object+", with id"+ids);
}

this.session.flush();
log.debug("Saved");
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 29, 2005 8:30 am 
Beginner
Beginner

Joined: Wed Sep 17, 2003 10:43 am
Posts: 48
I just want to port the following lines in 3.1:

Code:
ClassPersister cp = ((SessionImplementor) this.session).getPersister(object);
Serializable id = cp.getIdentifier(object);
Key objectKey = new Key(id, cp);


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 29, 2005 11:28 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Why did you ignore the documentation and use 3.1 _alpha_ if you don't use EJB3 previews?


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.