休眠的优点和缺点 [英] Pros and Cons of Hibernate

查看:112
本文介绍了休眠的优点和缺点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Project中,我打算使用Hibernate,但其中一个令人困惑的地方是:

In my Project iam about to use Hibernate but one create confusion is:

我在某处阅读的内容:

Hibernate具有自己的查询语言,即与数据库无关的hibernate查询语言 因此,如果我们更改数据库,那么由于HQL与数据库无关,因此我们的应用程序也将运行 HQL包含与数据库无关的命令

Hibernate has its own query language, i.e hibernate query language which is database independent So if we change the database, then also our application will works as HQL is database independent HQL contains database independent commands

这是否意味着在Java中使用Hibernate时我们不必编写存储的过程和视图?

Does it means that we dont have to write stored proceedure and views while using Hibernate in java?

推荐答案

简短答案:您不必编写任何查询和/或存储过程. (此外,您还可以在应用程序启动时休眠告诉您为您创建/更新所有必需表的方式.)

Short answer: You dont have to write any query and/or stored procedure. (Also you can hibernate tell to create/update all required tables for you, during application start.)

长答案:可以在没有任何手动定义查询的情况下使用Hibernate. (使用EntityManager,您可以简单地告诉hibernate从数据库中获取user.class的所有内容.)但是它也支持HQL和SQL查询.

Long answer: Hibernate can be used without any manual definition of a query. (Using the EntityManager, you can simple tell hibernate to get everything of user.class from the database.) However it does support HQL as well as SQL-Queries, also.

当您稍后切换到另一个数据库时,SQL查询当然将停止工作. HQL将适用于每个数据库,因为hibernate能够将HQL查询转换为任何(支持的)数据库语言.

SQL Queries of course will stop to work, when you switch to another database later on. HQL will work for every Database, because hibernate is able to translate HQL Queries to any (of the supported) Database Languages.

但是要注意:在我看来如果让冬眠完成所有工作,冬眠会太慢了. (在加载具有复杂关系的实体时,Hibernate会触发很多单选择查询)

But be aware: In my Opinion Hibernate is damn slow if you let hibernate do all the work. (Hibernate fires a LOT of single Select Queries, when loading entities with complex relations)

这篇关于休眠的优点和缺点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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