Whilst trying to create an API for my app I tried to make a query that takes a value passed in and then returns the response from the db.
@Query(value = "SELECT u FROM User u WHERE u.userID = ?")
User getUserById(String id);
I have created queries this way in other projects but cannot figure out why I get the following error on this project
JDBC style parameters (?) are not supported for JPA queries.
Positional parameters It's use question mark (?) to define a named parameter, and you have to set your parameter according to the position sequence. See example… String hql = "from Stock s where s. stockCode = ? and s.
Named query parameters are tokens of the form :name in the query string. A value is bound to the integer parameter :foo by calling setParameter("foo", foo, Hibernate. INTEGER); for example. A name may appear multiple times in the query string.
Query objects use SQL or Hibernate Query Language (HQL) string to retrieve data from the database and create objects. A Query instance is used to bind query parameters, limit the number of results returned by the query, and finally to execute the query.
have you tried this :
@Query(value = "SELECT u FROM User u WHERE u.userID = :id")
User getUserById(String id);
Encounter the same problem in HQL, in XML approach with positional Parameter
Exception: Legacy-style query parameters (?
) are no longer supported
HQL Query
String hql = "from Customer cust where cust.city=?";
Solution: Change the hql query as below
String hql = "from Customer cust where cust.city=?0";
And here we go!!
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