How to execute normal SQL query in Hibernate witho

2019-03-05 03:15发布

I have a pretty complex Join query to select few items from DB, and it doesn't involve any Update required back to this table. Which is why, I don't want to use the HQL (Hibernate Query Language, instead I want to execute as a simple SQL query.

Is that possible to execute a Normal SQL - Join query which involves 3 different tables in hibernate? I use Java - Struts framework.

If you say it is not possible then I have to stick to HQL and I would post here the query for which I would need your help in writing down HQL based class(tables) creations and HQL based Query string.

Also, if you could please give me an example query with couple or 3 table Joins and how to set the Parameters for the SQL.

2条回答
一夜七次
2楼-- · 2019-03-05 03:48

With JPA you can user entityManager.createNativeQuery(...) with Hibernate there's session.createSQLQuery(...)

查看更多
来,给爷笑一个
3楼-- · 2019-03-05 03:51

from below line of code you can use any Query with hibernate

its call Native SQL

session.createSQLQuery("SELECT * FROM table as a join table1 as b  on a.id = b.id ").list();

for more help go here

查看更多
登录 后发表回答