How can I search in Hibernate session not by id?

0 like 0 dislike
6 views
For example , I have user which has ID and Name.
To find the user id - session.get(User.class id);
But how to search a user by name , because if cltkfnm nfr session.get(User.class name) , it will generate an error.
by | 6 views

1 Answer

0 like 0 dislike
It is possible using Criteria API or HQL
1) hql
String name = "userName"; Query Query = session.createQuery("FROM User u where u.name = :name"); query setParameter("name", name);

2) through the criteria api, the query will be dynamically generated, and even for a simple query code will be more
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
asked Mar 23, 2019 by KriegeR
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
32,810 users