-->
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: Possible RFE: Session.updateProperty()?
PostPosted: Wed Apr 14, 2004 5:17 pm 
Newbie

Joined: Fri Feb 27, 2004 6:17 pm
Posts: 11
I'm looking at the API for updating objects, and was wondering if there is a way to easily accomplish an update for a single property.

For example, a method along the lines of:

Session.updateProperty(Object foo, String property, Object value);

Ideally, this mechanism would be smart enough to do things like throw a StaleObjectException if appropriate, etc. I can edit the operations of the properties for save/update in the mapping file, and I think this would probably(?) serve as a mechanism for overriding this as well (i.e. this could be used to update a property set to be ignored by default).

Is there a way to do this/recommended mechanism already? Or is this a reasonable RFE?

Cheers,

-Will


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 14, 2004 5:23 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You can read the Hibernate metamodel at runtime, e.g. for a Category POJO class:

Code:
Category category = ...;
ClassMetadata meta = sessionFactory.getClassMetadata(Category.class);
String[] metaPropertyNames = meta.getPropertyNames();
Object[] propertyValues = meta.getPropertyValues(category);

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: clarification
PostPosted: Wed Apr 14, 2004 5:32 pm 
Newbie

Joined: Fri Feb 27, 2004 6:17 pm
Posts: 11
Thanks for the super-fast reply, christian.

It's not a question of the metamodel (which is a great feature, btw). It's a question of issuing an update for a single property (while leveraging all of the rest of Hibernate's infrastructure).

For example, let's say that I've got an object with a great many properties. I'd like to just update one of them, instead of the whole record (perhaps several of the properties are relatively lengthy). Right now, I can get the object, change one property, and then save it, but I'd like to skip the intermediate get. Obviously, I'd still need to drag along the object ID (and possibly the version/timestamp).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 14, 2004 5:34 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Hm, don't know a good solution for that, as I can't see a good way to not load an object if you want to update it. You can use dynamic update, so if the UPDATE SQL is your problem, this will only UPDATE the changed columns.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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.