JDBC VS 休眠 [英] JDBC VS Hibernate

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

问题描述

我们在 Web 应用程序中使用 JDBC 已经很长时间了.我们使用它的主要原因是因为我们可以 100% 控制代码、sql 并通过我们的手修复问题.除此之外我们在数据库内部使用了触发器,数据库由DB专家单独开发.

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.

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

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

  1. Hibernate 无法与现有"数据库连接.它总是试图创造一个自己的.

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

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

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.

我们从不喜欢将表创建工作"交给 Java 代码.我们总是手动创建表.

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

我们可能不得不使用非常长且复杂的 SQL 语句.上次我们用了150多行的语句,连接了20多个表.我们怀疑当涉及到 Hibernate 时,我们是否会在这方面遇到麻烦.

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.

我们的 SQL 代码很好而且很标准.Hibernate 生成的代码对我们来说似乎有点脏.

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

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

We always use MySQL. Never use any other DB.

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

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

有很多外键Primary KeysComposite KeysUnique Keys等等在数据库中.在论坛中,有些人抱怨 Hibernate 搞砸了这些.

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.

我们决定尝试 hibernate 是因为有些人声称,你们是软件工程师吗?你们在使用已经死了的 JDBC !!."

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

考虑到这些,请让我知道以上几点是否真的正确(正如我所说,我是通过谷歌搜索、讨论等了解它们的).以及,Hibernate VS Java 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?

推荐答案

回答上面列出的问题:

1.Hibernate 无法与现有"数据库连接.它总是试图创造一个自己的.

这是错误的.Hibernate可以连接到现有的数据库,并且它并不总是尝试重新创建它.你只需要关闭像 hbm2ddl 这样的参数.自动.

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.我们的数据库可能会被不同平台(云、服务器、VPS、个人计算机)中的相同应用程序访问.在这种情况下,Hibernate 可能会因为缓存而产生问题.

Hibernate 有一个可调整的缓存,所以这也不是问题.

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

3.我们从不喜欢将表创建工作"交给 java 代码.我们总是手动创建表.

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

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.我们可能不得不使用非常长且复杂的 SQL 语句.上次我们用了150多行的语句,连接了20多个表.我们怀疑当涉及到 Hibernate 时,我们是否会在这方面遇到麻烦.

如果需要,您始终可以使用直接 JDBC 调用并通过休眠调用本机 SQL 查询.

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

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

同样,如果您必须调用一些逻辑复杂的 SQL 代码而不是自动生成的休眠状态 - 您可以这样做.

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

6.我们总是使用 MySQL.永远不要使用任何其他数据库.

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

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

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

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

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 休眠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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