0

I am new to the criteria api and am trying to build a select query where id matches id.

I would like to build this:

SELECT * FROM movie WHERE id = id(input var)

So far I have this with an input variable id as a long:

    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Movie> critQuery = criteriaBuilder.createQuery(Movie.class);
    Root<Movie> rootMovie = critQuery.from(Movie.class);
    critQuery.select(rootMovie).where(rootMovie.get("movieId"), id);

This will create errors and doesn't work. Any ideas how to make it work?

error: The method where(Expression) in the type CriteriaQuery is not applicable for the arguments (Path, Long)

legopiraat
  • 166
  • 1
  • 11
  • 3
    Add the error messages please. – Jens Oct 02 '14 at 11:48
  • I don't know how the API is supposed to work, but you're missing a close parenthesis in `critQuery.select(rootMovie).where(rootMovie.get("movieId", id);` -- does `get` actually take two arguments? – khelwood Oct 02 '14 at 11:51
  • made a little typo + added the error – legopiraat Oct 02 '14 at 11:57
  • Possibly a duplicate of http://stackoverflow.com/questions/10390115/compile-error-when-using-criteriabuilder –  Oct 02 '14 at 11:59

1 Answers1

0

Your where condition should look like this:

.where(criteriaBuilder.equal(rootMovie.get("movieId"), id));
cy3er
  • 1,699
  • 11
  • 14