Reputation: 16619
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.
Upvotes: 1
Views: 2233
Reputation: 39887
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.
Upvotes: 1
Reputation: 570295
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.
Upvotes: 1