I have the following that contains a NativeQuery where i need to set a parameter but somothing is wrong beacause parameter not set so the query is
SELECT movieId, title, genres FROM movies where title like '%%'"
so return all the rows. What is wrong
public List<T> findMovie(String keyword) {
Query q = getEntityManager().createNativeQuery("SELECT movieId, title, genres FROM movies where title like '%?%'", entityClass);
q.setParameter(1, keyword); //etc
return q.getResultList();
}
public List<T> findMovie(String keyword) {
Query q = getEntityManager().createQuery("SELECT movieId, title, genres FROM movies where title like :keyword", entityClass);
q.setParameter("keyword", keyword); //etc
return q.getResultList();
}
If you want to use positional params, use this syntax:
public List<T> findMovie(String keyword) {
Query q = getEntityManager().createQuery("SELECT movieId, title, genres FROM movies where title like ?1", entityClass);
q.setParameter(1, keyword); //etc
return q.getResultList();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With