I am currently creating a user defined search, my problem is that when it comes to normal sql( I run it in my database) it returns a result, but when it comes to HQL it does not return any result.
example. I made this query in SQL.
SELECT * FROM USER_PROFILES WHERE FIRST_NAME LIKE '%somevalue existinDb%';
this returns a value however with HQL Query Object
String someValue = "somevalue existinDb"
String temp_name = "%" +someValue + "%";
System.out.println(temp_name);
Query query = sess().createQuery(
"from UserProfile where firstName LIKE :temp_name").setParameter("temp_name",temp_name);
But However the HQL QUery Object does not render the same result as the SQL Query. Why is it like that?
Try this :
sess().createQuery(
“from UserProfile where firstName LIKE :temp_name”).setParameter(“temp_name”,’%’ + someValue + ‘%’);
And a much simpler method:
String someValue = “somevalue existinDb”
String temp_name = “%” +someValue + “%”;
Query query = session.createQuery(“from UserProfile where firstName LIKE ?” );
query.setString(0, temp_name);