gMale
gMale

Reputation: 17895

How do you make a join in Hibernate return a list instead of a two-dimensional list?

Hopefully, this is a simple question.

I'm doing a join in HQL along the lines of:

FROM Apple a, Orange o WHERE a.price = o.price AND a.price > 1.99

When I do this, I get back a collection representing the join. However, each element in the collection is actually another collection containing the related apple and orange.

What I want is a list of apples and what I'm getting is a list of apples and oranges. Logically, I'm looking for:

All apples priced greater than 1.99 only when
there is also an orange at the same price.

My actual problem is 50X more complex than this but I've simplified it to the basic problem. How do I correct/modify this HQL query to only give one type of object?

Upvotes: 1

Views: 1793

Answers (2)

hvgotcodes
hvgotcodes

Reputation: 120268

After leaving my comment I went to the documentation. Here is an example theta join from the docs

select p from NameList list, Person p
where p.name = some elements(list.names)

so it seems what you are doing should definitely be possible

Upvotes: 2

Frankie Ribery
Frankie Ribery

Reputation: 12153

Modify your query slightly:

SELECT a
FROM Apple a, Orange o WHERE ...

Upvotes: 2

Related Questions