tags:

views:

873

answers:

2

Hi all,

I'm having a kind of dummy problem, I need to make a @NamedQuery with a join with other table, some simple thing.

But in all my @NamedQuery I'm only dealing with my mapped Object/Table.

For example in my Object/Table Mapped cars:
@NamedQuery(name = Cars.GET_AVAILABLE_CARS, query =
"select c.id from Cars c where c.status = (select d.status from CarStatus d where d.color=red"

I'm trying to use: @SecondaryTables but no success for now.

One other thing that is working is give all things from other table as a parameter, but I don't think this will be good in performance.

Like: @NamedQuery(name = Cars.GET_AVAILABLE_CARS, query =
"select c.id from Cars c where c.status = :"+CarStatusParam)

Any tips?

Thanks in advance

A: 

A named query can use everything that an API query can use, so can clearly do subqueries. Which implementation of JPA ?

DataNucleus
A: 

What you are trying to do is not a join. It is a subselect. And in terms of performance it is as (in)efficient as getting the param beforehand.

If you insist, however, to use the subselect, the JPA Query Language support it. As it supports joins. Take a look here (at 7.11. Subqueries).

Bozho