• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Hibernate Criteria API Select some fields..

 
Ranch Hand
Posts: 494
Eclipse IDE Postgres Database Java
  • 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..
 
author and cow tipper
Posts: 5000
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
 
ranger
Posts: 17344
11
Mac IntelliJ IDE 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 Postgres Database Java
  • 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 ..
 
"To do good, you actually have to do something." -- Yvon Chouinard
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!