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: Partial refresh?
PostPosted: Tue May 19, 2009 7:59 am 
Newbie

Joined: Mon Jul 14, 2008 7:08 am
Posts: 18
I have a big object, containing pictures and some other heavyweigth data that is loaded from database by NHibernate. Also object contains some volatile data that can change very often. So I need the way to refresh not the whole object, but only part of it. And then update only this part back to database. Is it possible in NHibernate? Are there any workarounds?


Top
 Profile  
 
 Post subject: Re: Partial refresh?
PostPosted: Tue Jun 02, 2009 8:17 am 
Hi there.

You can set 'update=false' on your property mapping attribute.
Setting this, tells hibernate to NOT use this field on UPDATE SQL statement.

<property name="test"
column="TEST"
update="false" />


Top
  
 
 Post subject: Re: Partial refresh?
PostPosted: Thu Jun 04, 2009 6:47 am 
Hi There.

For example.

Car c = new Car();
c.name = "My Car";
c.color = "Red";
c.maxspeed = "200";

Then you use NHibernate save (persist) to persist your object.
After that you want to change (update) part of your object, corret?
So, you use NHibernate load, to get you object.

Car c = NHibernate.load(); //Check the rigth method call. This is an example.

And now you want to change one property.
c.name = "My new Car";

If you change the NHibernate property

<property name="color"
column="COLOR"
update="false" />

<property name="maxspeed"
column="MAXSPEED"
update="false" />

the SQL will be: UPDATE CAR SET NAME = 'My new Car' WHERE ID = ?;
You can use this to mapping properties you never want to update because its heavy.

and NOT UPDATE CAR SET NAME = 'My new Car', COLOR = 'Red', MAXSPEED = '200' WHERE ID = ?;

I guess that's what you want?
sorry if I got you wrong.

[]s


Top
  
 
 Post subject: Re: Partial refresh?
PostPosted: Thu Jun 04, 2009 7:18 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Afaik you only can disable updates and inserts for properties (as luiz mentioned), but you can't disable selection (except lazy loading for associations). You can put the heavy weight stuff in a separate class and try lazy-loading or some kind of load on demand.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: Partial refresh?
PostPosted: Tue Jun 09, 2009 11:00 pm 
Newbie

Joined: Mon Jul 14, 2008 7:08 am
Posts: 18
The problem is a little different: I have an object already loaded in memory (with heavy weight stuff) and I need to refresh (reload) particular property (for example Status property that can be changed by another user). When I execute ISession.Refresh() the whole object is loaded from database (maybe except lazy stuff), but what I need is only small SELECT to database. In the same time I can't change object model and do select="false" for all props except property Status


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.