How to execute sql query in sleep mode

I need to select an entry from the users_roles table and I am using hibernate. but I don't want to make a separate class in java for this, therefore

I am thinking about using plain sql. I can do this, or I have to do a java class for this. because I just extract the role for example

select role from user_roles where email = abc@cdf.com

any eaxmple of this will be fine

+3
source share
2 answers

Inside Hibernate, you should use the SQL-like Langauge HQL (Hibernate Query Language). It will look something like this:

From user_roles where email = abc@cdf.com

And retrieve the entire mapped object class for you.

edit: an alternative would be the following: Using native queries in Hibernate

+10
source

, 538603, ; , , / , Hibernate ( ...). , , HQL (, , ), www.mybatis.org, sql.

0

All Articles