-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: How to query using a collection: Expression.in() and QBE
PostPosted: Tue Feb 15, 2005 11:19 pm 
Newbie

Joined: Tue Feb 15, 2005 10:58 pm
Posts: 4
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.