-->
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.  [ 6 posts ] 
Author Message
 Post subject: Get only somme attributes from DB
PostPosted: Thu Aug 11, 2005 10:19 am 
Hi,
is it possible to get only somme attributes of an object from Database, instead of all attributes ?
I tested ISession.CreateSQLQuery() with version 0.8.4, but it does'nt work.

thank you
tj


Top
  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 1:39 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
If you are talking about lazy property fetching
read the topic Graph subset fetching

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 11, 2005 1:59 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
Do you perhaps mean something like this?
Code:
select user.FirstName, user.LastName from my.app.User as user

This would only return the FirstName and LastName properties of the User object, in an object array.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 19, 2005 4:56 am 
I thought that it is possible to get an Object instantiated by NHibernate that contains only the requested attributes.

thank you
tj


Top
  
 
 Post subject:
PostPosted: Mon Aug 22, 2005 1:58 pm 
Regular
Regular

Joined: Tue May 24, 2005 12:55 pm
Posts: 56
To the best of my knowledge, it is not possible to populate a subset of properties on a mapped object using the base NHibernate framework. HQL with a SELECT statement will return an object array of the SELECT items values, even if they are all from the same object. (as was previously stated)

If you have a lot of need for this, you may want to look at integrating the iBATIS framework http://ibatis.apache.org/index.html into your DAL. Anyway you look at it it's gonna require a bit of work.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 22, 2005 6:32 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
See http://nhibernate.sourceforge.net/forum/viewtopic.php?t=604 about dynamic instantiation.

Basically, you need to do this:
1. Create an object where the constructor takes the types you want to select.
2. Import it in your mappings
3. Use the "select new SubsetObject( foo.A, foo.B ) from BigObject foo where ...." syntax. See this for a better explanation.


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