The moose likes Object Relational Mapping and the fly likes Hibernate Criteria API Select some fields.. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "Hibernate Criteria API Select some fields.." Watch "Hibernate Criteria API Select some fields.." New topic
Author

Hibernate Criteria API Select some fields..

Leonardo Carreira
Ranch Hand

Joined: Apr 07, 2009
Posts: 478
Hi Friends...

Currently, iam learning for using Hibernate Criteria API for retrieving data from Database...
how to select some field with Criteria API?..
example i have a table which has 5 columns..
how to get of the some field of the table?..

i created the Criteria API like this :


but the query which resulted is

Select columnA, columnB, columnC, columnD, columnE
From MyTable
Where columnA=?


How to get some field by using CriteriaAPI?..
example.. i want to retrieve query by using select like this..


Select columnA, columnB
From MyTable
Where columnA=?


Thanks in advance..


Sorry, perhaps my english language isn't too good.. Prepare for SCJP 6, Please God help me.. ☼
References : [Java.Boot] [JavaChamp] [JavaPrepare]
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4924

So, what you're going to get back from the criteria query is your object, rather than an individual column. With the object, just call the getter.

Simple Tutorial on How To Use The Hibernate Criteria API

-Cameron McKenzie

Author of Hibernate Made Easy, What is WebSphere???, JSF 2.0 Made Easy and the SCJA Certification Guides
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 16331

To add to Cameron's response. It is easiest and quickest to do it with getting back the objects.

Only in the case of a "report" do you want to do selection of certain fields, and to do those you use the Projections Criterion objects.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Leonardo Carreira
Ranch Hand

Joined: Apr 07, 2009
Posts: 478
@Cameron and @Mark

Okay.. Thanks all..

it could ran well now.. yap i have to learning extra hard..

Thanks in advance ..
 
 
subject: Hibernate Criteria API Select some fields..
 
MyEclipse, The Clear Choice

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture