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.