Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to execute sql query in hibernate

i have to select the record from table users_roles and i am using hibernate. but i don't want to to make the separate class in java for that , so

i am thinking of using plain sql . can i do it or i have to make the java class for that . because i i just to extract the role like

select role from user_roles where email = [email protected]

any eaxmple of that would be fine


1 Answers

Within Hibernate, you have to use the SQL-like langauge HQL (Hibernate Query Language). This would look something like:

From user_roles where email = [email protected]

And retrieve the whole mapped entity class for you.

edit: an alternative would be this: Using native queries in Hibernate

like image 199
Michael Schubert Avatar answered Jun 29 '26 06:06

Michael Schubert