Hibernate version:2.1.8
Oracle 10g
Java 1.5
I have a collection (Set) of objects<Book> and I want to query the db looking for matches. For example, I want some sql that looks like:
select BOOK_ID, BOOK_NAME
from BOOKS
where BOOK_NAME in ("Atlas Shrugged", "Neuromancer");
Hibernate's Example (QBE) is perfect if I have a single Book object, but doesn't work if I have a collection of Books I want to search on.
The Expression.in(propertyName, collection) works ONLY if I first generate a new colllection of Strings (for book name). This works, except I have to iterate over the entire collection of books to get the values for the IN clause collection -- expensive, especially since the Expression.in call has to iterate over the collection anyway.
I want to do something like Expression.in(propertyName, BookCollection), where the BookCollection is a set of Book objects and Expression builds the approriate IN clause by pulling the properyName values from each Book in my collection.
In essence, I would like to combine the concepts of QBE/Example and Expression.in(). I have a collection of Hibernate entities(Books) that I want to use as "examples" to build an "in" clause. I don't care if it is using Example and Expression, I just don't want to iterate over the BookCollection to generate another collection that is then iterated over...
Make sense? This is kind of hard to articulate. Please respond if you have any idea of what I am trying to do or have a possible solution.
TIA,
E
|