Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting a single property from criteria query

 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
Is it possible to get a single property instead of the whole object using Criteria queries ?
session.createCriteria("book.title")
instead of :
session.createCriteria(Book.class)
?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From a criteria based query? Assuming this is Hibernate we are talking about, I don't think so. You can do this with HQL though. Why do you just need one property rather than the object?
[ April 24, 2007: Message edited by: Paul Sturrock ]
 
Hussein Baghdadi
clojure forum advocate
Bartender
Posts: 3479
Clojure Mac Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you just need one property rather than the object?

With HQL, you can write :
select book.title from Book book
So, I thought, what about Criteria ?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fair enough. Don't think its possible though.
 
Jaap v Hengstum
Greenhorn
Posts: 6
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Getting a single property in a Criteria can be done using setProjection() :

Above criteria will get only the title(s) of the selected book(s).
 
saranga rao
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

You can also done this by..

Joining the table like createAlias() of the same table.

Regards
Saranga
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic