-->
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.  [ 1 post ] 
Author Message
 Post subject: Getting subset of columns
PostPosted: Fri May 23, 2008 11:00 am 
Newbie

Joined: Tue Apr 01, 2008 3:52 pm
Posts: 5
I am using Hibernate in JBoss with Annotations and my question is:

Is it possible to get objects back from a hibernate call that only have a certain columns set?

I.E. Some of my tables are very wide, and I might only need a couple of columns populated in the objects. Is there a way to get hibernate to return an object with only a subset of the columns set?

I tried to use Projections for this, and it works except that the list() method is returning a list of Strings containing the values from the object, but I wanted to see if I could get a list of the actual objects with just those columns populated....

Here some code:

Code:
ProjectionList projectionList = Projections.projectionList();
projectionList.add( Projections.property( "partno" ) );
projectionList.add( Projections.property( "descr" ) );
           
List list = hsession.createCriteria( PartFileEntity.class ).add( Restrictions.eq( "partno", "004" ) ).setProjection( projectionList ).list();


My hope was that this would get returned as a List contain one PartFileEntity object with just the "partno" and "descr" column values set. Instead I get back an Object array with 2 elements, the first containing the value for partno and the second containing the value for descr.

Any advice here would be most appreciated.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.