views:

30

answers:

2

Hi All,

I want to know whether I can join 2 named queries in JPA. As an example I have two following named queries

1 - Get all the active users 2 - get all the users for a given company

Is it possible for me to join above two named queries and get

get all the active users for a given company.

If possible pls send me some references

thanks in advance

cheers

sameera

+1  A: 

Don't use NamedQuery for this. Directly passing a query string to the method is your best bet.

You must understand that the method createNamedQuery(String name) takes name of a named query. Whereas, createNamedQuery(String qlString)takes a query string, so this fits your need.

Or

Create a separate NamedQuery for this very purpose.

Adeel Ansari
Why would the poster want to use HQL ? He says JPA, not Hibernate.
DataNucleus
@DataNucleus: Oh yeah. Thats a `default` in my default settings. Sorry, modified now.
Adeel Ansari
thanks Adeel, I'll check on that
sameera207
+1  A: 

Is it possible for me to join above two named queries and get all the active users for a given company.

No, that's not possible. Either write a smart named query that can take parameters to express all cases (if possible) or use several named queries.

And if you are using JPA 2.0, the Criteria API might be another (better) option to write dynamic queries.

Pascal Thivent