Question

Here is my select from the database:

SELECT * FROM testlogging.employees 
where
  EMPLOYEE_NO in (
    select EMPLOYEES_EMPLOYEE_NO from testlogging.test_logging
    where ID in (
      select TEST_LOGGING_ID from testlogging.test_logging_detail 
      where APPROVAL_LEVELS_ID = '4'
    )
)

How would i do this in JPA?

SELECT e FROM Employees e ???

Pas de solution correcte

Autres conseils

If you're asking for the JPA INsyntax you would do this:

SELECT e FROM Employees e where e.employee_no IN :employeelist

as well ass

query.setParameter( "employeelist" , yourlist );

and of course build yourlist accordingly. If you don't really need to parameterize the inner queries, you can disregard this and just go the straight forward route.

Cheers,

Just in case you're using the JPA Criteria metamodel queries, the IN usage goes like this

CriteriaQuery<Pet> cq = cb.createQuery(Pet.class);
Root<Pet> pet = cq.from(Pet.class);
cq.where(pet.get(Pet_.color).in("brown", "black"));

as stated at http://docs.oracle.com/javaee/6/tutorial/doc/gjivm.html

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top