-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to fetch specific column using Criteria class?
PostPosted: Fri Jul 28, 2006 10:18 am 
Newbie

Joined: Fri Jul 28, 2006 9:52 am
Posts: 12
Iam new to hibernate. How do i specify the column which i want to fetch.
is it possible to specify the specific column name to fetch the datas using criteria class??





Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 28, 2006 10:50 am 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
You can use below example to retrieve only three columns from two tables which have parent-child relatioship. If you notice in ProjectionList, i am selecting two columns from parent table and one column from child table.

Code:
Criteria ct = session.createCriteria( TableOne.class, "t_one" );
ct.add( Restrictions.eq( "t_one.propertyOne", objectOne ) );
ct.add( Restrictions.eq( "t_one.propertyTwo", objectTwo  ) );
ct.createCriteria( "t_one.collectionProperty", "colls" ); // this maps to join table or TableTwo.class
ProjectionList pl = Projections.projectionList();
pl.add( Projections.property( "t_one.propertyOne" ) );
pl.add( Projections.property( "t_one.propertyThree" ) );
pl.add( Projections.property( "colls.propOne" ) );
ct.setProjection( pl );

List results = ct.list();


And you should be aware that objects in retrieved List will be Object[] array and not any persistent class.


Top
 Profile  
 
 Post subject: Got it .. thanks...But still one more doubt?
PostPosted: Sun Jul 30, 2006 5:48 am 
Newbie

Joined: Fri Jul 28, 2006 9:52 am
Posts: 12
Yeah i was trying projections only, but i was trying to get the persistant object from the list. Thats y i was not able to get the result and i put the query. After seeing your last line of your reply i came to know that the list will contain only the object array and not the persistant class array.

l got one more question... may be silly... is there any way to map it to persistant class and the list will contain the persistant array with only the columns which we are specifying???


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