如何在不使用HQL的情况下在Hibernate中执行正常的SQL查询? [英] How to execute normal SQL query in Hibernate without HQL?
问题描述
我有一个非常复杂的Join查询来从DB中选择几个项目,并且它不涉及任何需要更新回到这个表格。
这就是为什么我不想使用HQL(Hibernate查询语言),而是想作为一个简单的SQL查询来执行。
是那个可能执行一个正常的SQL - Join查询,其中包含3个不同的表在Hibernate中?我使用Java - Struts框架。
如果你说这是不可能的,那么我必须坚持HQL,我会在这里发布查询,我需要你帮忙写下基于HQL的类(表)创建和基于HQL的查询字符串。
另外,如果您可以请给我一个示例查询,其中包含两个或三个表连接以及如何设置SQL的参数。
使用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(...)
这篇关于如何在不使用HQL的情况下在Hibernate中执行正常的SQL查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!