HQL与SQL / Hibernate netbeans HQL编辑器 [英] HQL vs. SQL / Hibernate netbeans HQL editor

查看:140
本文介绍了HQL与SQL / Hibernate netbeans HQL编辑器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我发现它比使用plain更难以理解SQL(我习惯了)



PLUS:我发现NetBeans HQL编辑器非常令人讨厌,我很难在HQL中产生正确的查询,然后在SQL ,为什么显示的SQL与实际的SQL语句不同?



那么为什么要使用它? - 众所周知,hibernate是非常广泛的资源,我相信hibernate是我们的应用程序经常耗尽内存的原因,例如在重新部署过程中。例如..



我非常有兴趣知道为什么我应该使用Hibernate而不是纯SQL(mysql)语句!?

也许一个用于hibernate查询的好链接会be nice;),我正在使用这个atm:



但是也对任何解释查询设置,映射,底层构造等的好链接感兴趣。 b
$ b

最好的问候
Alex

解决方案

HQL是面向对象的,处理表示数据库表的Java对象的目的。
一个基本的优点是,您可以在HQL查询中使用像:orderNumber 这样的占位符(使用冒号simbol),并用变量的值替换。例如:

  int orderNumber = 685412; 
清单<订单> l =
session.createQuery(from Order where orderNumber =:orderNumber)
.setParameter(orderNumber,orderNumber).list();

通过这种方式,您可以修改 orderNumber in一个简单的方法,避免经典的

  String query =select * from Order where orderNumber =+ orderNumber +... ; 



使用MySQL语法的Morover有时会使您的代码无法重用,如果将数据库迁移到另一个DBMS。
无论如何,我还是不太相信HQL的偏好。


这里可以找到完整的语法定义。


I am teaching my self hibernate, and am quite confused of why i can not just write simple SQL queries.

I find it rather more confusing to use than plain SQL (what I am used to)

PLUS: The NetBeans HQL editor I found pretty annoying, It is harder for me to produce a right query in HQL, then in SQL, and why does the shown SQL differ from actual SQL statements ?

So why use it ? - As it is known that hibernate is very resource extensive, and I believe that hibernate is the reason for our app to running out of memory very often, as during the process of redeploying e.g...

I am very interested in knowing why I should use Hibernate and not plain SQL (mysql) statements !?

And maybe a good link for hibernate queries would be nice ;), I am using this one atm:

But also interested in any good link explaining the setup of the queries, the mapping, underlying construction etc..

Best Regards Alex

解决方案

HQL is object oriented and it's done with the purpose of working on the Java objects representing your DB tables. A basic advantage is that you can put placeholders like :orderNumber (using the colon simbol) in the HQL query and replace with the value of a variable. For example:

int orderNumber = 685412;
List<Order> l= 
    session.createQuery("from Order where orderNumber = :orderNumber")
    .setParameter("orderNumber",orderNumber).list();

In this way you can modify orderNumber in a simple way, evoiding the classical

String query = "select * from Order where orderNumber = " + orderNumber + "...";

Morover using MySQL syntax would sometimes turn your code not reusable if you migrate your DB to another DBMS. Anyway I'm still not so convinced about the preference on HQL.

Here you can find the full grammar definition.

这篇关于HQL与SQL / Hibernate netbeans HQL编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆