| Author |
Getting a single property from criteria query
|
Hussein Baghdadi
clojure forum advocate
Bartender
Joined: Nov 08, 2003
Posts: 3334
|
|
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
Joined: Apr 14, 2004
Posts: 10336
|
|
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 ]
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
Hussein Baghdadi
clojure forum advocate
Bartender
Joined: Nov 08, 2003
Posts: 3334
|
|
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
Joined: Apr 14, 2004
Posts: 10336
|
|
|
Fair enough. Don't think its possible though.
|
 |
Jaap v Hengstum
Greenhorn
Joined: Apr 25, 2007
Posts: 6
|
|
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
Joined: Apr 24, 2007
Posts: 49
|
|
hi You can also done this by.. Joining the table like createAlias() of the same table. Regards Saranga
|
 |
 |
|
|
subject: Getting a single property from criteria query
|
|
|