使用 Hibernate 时数据库的成熟度有多重要
我想知道使用Hibernate框架时数据库有多重要。例如,在比较 Oracle 和 MySql 时,独立数据库存在巨大差异,但当数据库隐藏在 Hibernate 后面时,我看不出有很大差异。将 Hibernate 与更高级的数据库系统结合使用有什么优势?
谢谢您的回答。
I would like to know how much does the database matters when using Hibernate framework. There is a huge difference in standalone databases when comparing for example Oracle and MySql, but I can't see a big difference when database is hidden behind Hibernate. What would me advantages of using Hibernate in conjunction with more advanced database systems?
Thank you for answers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Hibernate 或多或少是一种映射语言,它允许您在代码中调用 Hibernate 方法,并让 Hibernate 库将这些方法调用转换为适当的 JDBC 调用(或多或少)。
因此,只要 Hibernate 知道如何将其 API 调用转换为给定 RDBMS 的正确、高效的 SQL,那么这就不重要了。如果 RDBMS 不断更改功能等,那么它的“成熟度”可能会成为一个问题 - 但仅限于相应的 Hibernate 方言需要不断更新以处理该特定版本。
在大多数情况下,如果您只是使用符合 SQL 标准的方面,那么您不应该看到 Hibernate 的问题,因为它应该能够很好地处理最低公分母的内容。也就是说,如果您专门使用此 RDBMS 来获取其“更高级”的功能,您可能会对 Hibernate 没有利用它们感到失望(取决于很酷的功能是否完全是内部的,例如非常高性能的查询优化器) ,或者是外部的,例如一些新的 SQL 命令)。
Hibernate is more or less a mapping language that lets you call Hibernate methods in your code, and have the Hibernate library convert these method calls into the appropriate JDBC calls (more or less).
So, as long as Hibernate knows how to convert its API calls into the correct, efficient SQL for a given RDBMS, it shouldn't matter. The "maturity" of the RDBMS may be an issue if it keeps changing features, etc. - but only in the sense that the corresponding Hibernate dialect would need to be continuously updated to deal with that particular version.
In most case, if you're just using aspects that conform to the SQL standard, you shouldn't see a problem with Hibernate as it should be able to handle lowest-common-denominator stuff just fine. That said, if you're using this RDBMS spceifically for its "more advanced" features, you may be disappointed that Hibernate doesn't take advantage of them (depending on whether the cool features are entirely internal, such as a very performant query optimizer, or are external such as some new SQL commands).
Hibernate 只是一个工具,它可以让你与 db 的交互比简单的 jdbc 更容易。但 hibernate 不会为它做数据库工作:它无法提高数据库性能或为其添加一些功能。所以数据库仍然是一个重要的选择。
Hibernate is just a tool to make your interaction with db easier than simple jdbc. But hibernate won't do the db work for it: it can't improve the db performance or add some features to it. So database is still an important choice to make.
除了 RDBMS 的内在特性之外,差异还在于所使用的特定“方言”的功能。
Besides the intrinsics of the RDBMS, the difference lies in the capabilities of the specific "dialect" that will be used as a consequence.
我可以权威地说,这非常重要。我不确定您是否会发现 MySQL 和 Oracle 在应用程序级别上有很大差异,但如果您“向下”查看 DBMS 列表并访问 SQLite 或 H2 等数据库,它们的内部工作原理会带来很多变化 em> 的差异取决于您存储的对象类型和您创建的访问模式——即使 Hibernate 隐藏了数据库的怪癖。锁定机制、并发能力、事务处理方式、索引构建/利用/交互等细节将影响应用程序的运行效果——有时会影响很大。例如,由于我们发现的限制,我们必须将正在运行的系统上的千兆字节数据从 H2 迁移到 MySQL——尽管我们到处都使用 hibernate。
显然,每个数据库都有自己的功能集,包括复制、分片、整体性能、成本、管理工具等,这些也必须考虑在内。
I can say with authority that it can matter very much. I'm not sure if you will see much difference at an application level between MySQL and Oracle but if you go "down" the DBMS list and get to databases such as SQLite or H2, their internal workings make a lot of difference depending on the types of objects you store and the access patterns you make -- even with hibernate hiding the database eccentricities. The particulars around the locking mechanisms, concurrency abilities, how they handle transactions, index building/utilization/interaction, etc. will impact how well your application will function -- sometimes significantly. For example, we had to migrate gigabytes of data on a running system from H2 to MySQL because of limitations that we uncovered -- even though we use hibernate everywhere.
Obviously, also, each database has its own feature set wrt replication, sharding, overall performance, cost, admin tools, etc. that must also be taken into account.