且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在不使用HQL的情况下在Hibernate中执行正常的SQL查询?

更新时间:2022-11-04 13:43:56

使用JPA,你可以使用entityManager.createNativeQuery(...)和Hibernate,这里有session.createSQLQuery(...)


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.

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