If you have mapped models and CriteriaQueries, wrap the CriteriaQuery in JpaCriteraBuilder and configure JpaDao with your model class.
Don’t include pagination or order in Queries, JpaDao already do it for you based on the requested page. Both implementations only load one page
at time.
use:
page.setPageSize(int size); // to set the page size,
page.setPage(int page) ; // to set the requested page.
page.setSortName(String propertyPath); // to set the order property "customer.order.price" for example,
page.setFilter(Filter filter); // to set the filter bean
...
and so on.
To build the sample code use mvn package and mvn jetty:run to try it.
Hi Jean-Francois,
i’m trying your add-on, but I can’t find how to use my Hibernate criteria, TypedQuery,NamedQuery with your container.
Can you help me?
// Actual Code
CriteriaQueryDefinition<Anagrafiche> cqd = new CriteriaQueryDefinition( Anagrafiche.entityManager() , true, 30, Anagrafiche.class);
CriteriaContainer cc = new CriteriaContainer(cqd);
cbDestinatario.setContainerDataSource( cc );
Types of code to be integrated with criteriacontainer
TypedQuery
public static TypedQuery<Anagrafiche> Anagrafiche.findCustomer() {
EntityManager em = Anagrafiche.entityManager();
TypedQuery<Anagrafiche> q = em.createQuery("SELECT o FROM Anagrafiche AS o WHERE o.indCli = true", Anagrafiche.class);
return q;
}
NamedQuery
@NamedQuery(name = "User.userExists_LoginID",
query = "SELECT user FROM User user " +
"WHERE user.loginID = :loginID " )
JPA 2.0 has its own notion of Criteria query, which is not the same as Hibernate. The two approaches are similar in spirit, but different in the actual API.
Your original question only mentioned CriteriaQuery, and made reference to JPA, so I made my suggestion.
The JPA Criteria LazyQueryContainer is meant for JPA 2.0 Criteria Query, and not for the Hibernate queries you list. Should you want to use it anyway, there is an example application with several usage patterns. Look for the “defineQuery()” method for examples.