Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Criteria API Select some fields..

 
Leonardo Carreira
Ranch Hand
Posts: 494
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Leonardo Carreira
Ranch Hand
Posts: 494
Eclipse IDE Java Postgres Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Cameron and @Mark

Okay.. Thanks all..

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

Thanks in advance ..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic