JDBC VS Hibernate [英] JDBC VS Hibernate

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

问题描述

我们已经在我们的Web应用程序中使用JDBC很长一段时间了。我们使用它的主要原因是因为我们拥有100%的代码控制权,sql和我们手中的东西。除此之外,我们在数据库中使用了触发器,而数据库是由数据库专家分别开发的。



然而现在很多人推荐使用 Hibernate 所以我们也考虑过使用它。但是,我们发现了以下问题。


  1. Hibernate无法连接Existing数据库。我们的数据库可能会被不同平台上的相同应用程序(云,服务器,VPS,个人计算机)访问。

  2. )。在这种情况下,Hibernate可能会因为缓存而出现问题。 我们从不喜欢将表创建工作赋予java代码。我们总是手动创建表。 我们可能不得不使用非常长且复杂的SQL语句。上次我们使用了超过150行的语句,加入了超过20个表格。我们怀疑当涉及到Hibernate时我们是否会遇到麻烦。 我们的SQL代码很好,很标准。 Hibernate生成的代码对我们来说似乎有点脏。 我们总是使用MySQL。切勿使用任何其他数据库。 我们创建的应用程序需要与医疗相关的最大安全性。如果至少有一条数据记录被泄露,我们就完成了。 主键组合键唯一键等等等在数据库中。在论坛中,有些人抱怨说Hibernate与这些混淆。 我们决定尝试hibernate,因为有些人声称你是软件工程师吗?你使用的已经死了 JDBC !!




    考虑到这些,请让我知道上述观点是否真的是正确的(正如我所说的,我通过谷歌搜索,讨论等来了解它们)。而且,Hibernate VS Java JDBC的优缺点是什么?

    解决方案

    回答上面列出的问题:



    1。 Hibernate无法连接现有数据库。它总是试图创建一个它自己的。



    这是错误的。 Hibernate 可以连接到一个现有的数据库,它并不总是试图重新创建它。您只需转动 hbm2ddl等参数即可。 auto



    2。我们的数据库可能会访问不同平台(云,服务器,VPS,个人计算机)中的相同应用程序。 Hibernate在这种情况下可能会因缓存而出现问题。

    $ Hibernate有一个可调缓存,所以这也不是问题。 b
    $ b

    3。我们从不喜欢将表格创建工作提供给java代码。我们总是手动创建表格。



    没问题。见上文第1页。此外,还有几个方便的库创建和更新间接表(例如 liquibase ),它可以完美地与hibernate结合使用。



    4。我们可能不得不使用非常长且复杂的SQL语句。上次我们使用了超过150行的语句,加入了超过20个表格。我们怀疑在Hibernate中是否会遇到麻烦。



    您可以使用直接JDBC调用并通过hibernate调用本地SQL查询,if它是neeeded。



    5。我们的SQL代码很好,很标准。 Hibernate生成的代码对我们来说似乎有点脏。



    同样,如果您必须调用一些逻辑复杂的SQL代码而不是自动生成的hibernate,可以做到这一点。



    6。我们总是使用MySQL。切勿使用任何其他数据库。



    完全没有问题。 Hibernate有特殊的MySQL方言支持: org.hibernate.dialect.MySQLDialect



    7。我们创建的应用程序需要最大的安全性,与医疗相关。如果至少有一条数据记录泄露,我们就完成了。



    安全问题与ORM技术无关。 Hibernate 是纯数据库JDBC调用和程序员工具之间合乎逻辑和方便的面向对象层。它不影响通用网络安全。


    We have been using JDBC for a very long time in our web applications. The main reason we used it is because we have 100% control over the code, sql and fix things by our hands. Apart from that we used triggers inside the database, and the database is developed separately by DB experts.

    However many now recommend using Hibernate so we also thought about using it. But, we found the below issues.

    1. Hibernate cannot connect with an "Existing" database. It always try to create a one of its own.

    2. Our database might access by same application which is in different platforms (cloud, server, VPS, Personal Computer). Hibernate can make problems because of its caching in this situation.

    3. We never like to give the "table creating work" to the java code. We create tables manually, always.

    4. We might have to use very long and complex SQL statements. Last time we used an statement with more than 150 lines, joining more than 20 tables. We doubt whether we will face troubles in this when it comes to Hibernate.

    5. Our SQL code is nice and standard. Hibernate generated code seems to be bit dirty for us.

    6. We always use MySQL. Never use any other DB.

    7. The application we create require max security, related to medical. If at least one data record is leaked, we are done.

    8. There are lot of foreign keys, Primary Keys, Composite Keys, Unique Keys etc etc in database. In forums, some complained that Hibernate messed with those.

    9. We decided to try hibernate because some people claims, "Are you Software Engineers? You are using already dead JDBC !!. "

    Considering these, please let me know whether the above points are actually true (as I said, I got to know them via googling, discussion etc) or not. And, what are the pros and cons of Hibernate VS Java JDBC?

    解决方案

    Answering issues listed above:

    1. Hibernate cannot connect with an "Existing" database. It always try to create a one of its own.

    This is wrong. Hibernate can connect to an existing database, and it doesn't always try to recreate it. You just should turn of parameter like hbm2ddl. auto.

    2. Our database might access by same application which is in different platforms (cloud, server, VPS, Personal Computer). Hibernate can make problems because of its caching in this situation.

    Hibernate has an adjustable cache, so this is also not a problem.

    3. We never like to give the "table creating work" to the java code. We create tables manually, always.

    No problem. See p.1 above. Furthemore there are several convinient libraries for indirect table creation and update (e.g. liquibase) which can be used in couple with hibernate perfectly.

    4. We might have to use very long and complex SQL statements. Last time we used an statement with more than 150 lines, joining more than 20 tables. We doubt whether we will face troubles in this when it comes to Hibernate.

    You can always use direct JDBC calls and invoke native SQL queries via hibernate, if it is neeeded.

    5. Our SQL code is nice and standard. Hibernate generated code seems to be bit dirty for us.

    Again, if you have to invoke some logic complicated SQL code instead of hibernate auto-generated - you can do it.

    6. We always use MySQL. Never use any other DB.

    Not a problem at all. Hibernate has special MySQL dialect support: org.hibernate.dialect.MySQLDialect.

    7. The application we create require max security, related to medical. If at least one data record is leaked, we are done.

    Security issues aren't related to ORM techniques. Hibernate is just logical and convinient object-oriented layer between pure database JDBC calls and programmers tools. It doesn't influence somehow on common net security.

    这篇关于JDBC VS Hibernate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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