문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top