SQL syntax error using JPA Criteria Query

1

Good morning,

I am trying to launch a SQL query that retrieves all the Sites associated with a user, using the following JPA code:

CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Site> query = cb.createQuery(Site.class);
Root<Site> fromSite = query.from(Site.class);
Join<UserSiteClientRolePK, Integer> joinUser = fromSite
    .join(Site_.siteClients)
    .join(SiteClient_.usersSitesClientsRoles)
    .join(UserSiteClientRole_.id)
    .join(UserSiteClientRolePK_.userid);
query = query.select(fromSite);
query = query.where(cb.equal(joinUser, userid));
TypedQuery<Site> typedQuery = em.createQuery(query);
List<Site> sites = typedQuery.getResultList();

However, when testing the code using the OpenJPA 2.4.0 implementation I get the following exception in my JUnit test:

<openjpa-2.4.0-r422266:1674604 fatal general error> 
org.apache.openjpa.persistence.PersistenceException: 
ERROR: error de sintaxis en o cerca de «AND»

Position: 440 {prepstmnt 737085888 
SELECT ...
WHERE (t3.userid = ? AND  AND ) [params=?]} [code=0, state=42601]

For some reason, OpenJPA is including erroneous SQL code "AND AND)" at the end of the SQL script, and I can not find the reason.

I'm going crazy with this. Can someone help me, please?

Thank you very much. Greetings.

    
asked by Raúl Carrasco 14.12.2016 в 20:16
source

0 answers