IntelliJ open source
[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Win a copy of Flex 4 in Action this week in the Flex forum!
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Object Relational Mapping
 
RSS feed
 
New topic
Author

Hibernate Criteria API Select some fields..

Leonardo Carreira
Ranch Hand

Joined: Apr 07, 2009
Messages: 475

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
Bartender

Joined: Aug 26, 2006
Messages: 4601

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???, Portlet Programming Made Easy and the SCJA Certification Guides
My Hibernate and JPA Tutorials * My Mock Java Certification Exams * My Online Java Tutorials * My CBT Portlet Tutorials.

Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Messages: 14893

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
Spock's Beard - Foabia app - Money Mgt Calculator - Paper Clips
How to Ask Questions the Smart Way FAQ
Leonardo Carreira
Ranch Hand

Joined: Apr 07, 2009
Messages: 475

@Cameron and @Mark

Okay.. Thanks all..

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

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]
 
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Object Relational Mapping
 
RSS feed
 
New topic
replay challenge