5

I am begining a new project that i think will last for some years. Am in the point of deciding the ORM framework to use (or whether to use one at all). Can anyone with experience tell me whether orm frameworks are used in realworld applications. The problem i have in mind is this: The orm tool will generate for me tables and columns etc as i create and modify my entities. However, after the project has gone live and is in production, certain database changes will not be possible. Can this hinder the advancement of the project. If i had used a framework like ibatis for example, i know i would only need to adjust the sql statements based on the database changes. Can someone tell me whether ORM tools have survived the live environment. At my office, we use java based ERP that was done long ago and it was never done using any ORM framework.

Regards. Josh

4

4 回答 4

2

仅将自动生成的模式用于早期开发和原型设计。生成的 DDL 几乎永远不会满足任何有经验的 DBA。此外,数据库的寿命将比当前的应用程序代码更长,因此花时间在其设计上通常是值得的。

在选择映射器时,请选择灵活的映射器,并远离对象痴迷的映射器,因为它们通常只支持有限的数据库定制。Hibernates 糟糕的存储过程集成浮现在脑海中,JPA 缺乏对自定义类型映射器的支持也是如此。

IBatisEclipseLink这样的对象映射器是安全的选择,因为它们允许您映射几乎任何东西,确保您可以创建出色的域模型和漂亮的模式设计。另请注意,Spring JDBC已经走了很长一段路(尤其是非常方便的SimpleJDBCTemplate),因此虽然从技术上讲它不是 ORM,但它确实允许您做任何您想做的事情,而无需编写繁琐的 JDBC 样板代码。

于 2010-04-20T09:08:55.020 回答
2

ORM 在实际应用中被广泛使用。您提到的架构更改问题通常通过以下两种方式之一处理:

  1. 正如之前的答案所建议的,您可以在数据库中手动维护架构,并让 ORM 更新其架构以匹配它在数据库中看到的内容。

  2. 您可以让 ORM 对照它自己的有关对象模型的信息检查数据库的模式,并生成必要的查询以在有任何更改时进行更新。

以我的经验,任何体面的 ORM 都应该能够处理 #1 并且大多数似乎能够管理 #2,但它并不那么普遍。

至于哪个更好,嗯……这在很大程度上取决于您如何看待数据库和对象模型之间的关系。

如果您的主要兴趣是数据库,并且您使用 ORM 围绕表和字段提供 OO 包装器以使它们更易于访问,那么您可能希望使用 #1 并保持对数据库的完全控制。

另一方面,如果您将对象模型视为至高无上的,并且主要将数据库用作一种愚蠢的持久性机制,而 ORM 用于简化该任务,那么您可能希望使用 #2 以便您可以专注于对象模型,而不必担心底层数据库细节。或者,您可能想查看键/值存储、对象图持久性引擎或其他形式的 NoSQL 数据库,以便更好地支持直接的对象持久性,而完全不必担心数据库端的模式更改。

于 2010-04-20T09:13:16.303 回答
1

I have used for several years in production Hibernate + JPA. I have never relied on the ORM schema generation though and I think that this is bad practice in general since you're not totally in control of the schema this way and ORM will not always generate the optimal schema. Using something like Liquibase for tracking schema migrations in a much better idea IMO.

于 2010-04-20T08:53:53.137 回答
0

我已经使用 Hibernate 几年了,我对它非常满意。我只使用模式生成器来创建一个全新的数据库,但对于升级,我使用人造 sql 脚本。

我认为不可能可靠地自动升级模式:例如,如果您重命名一个字段,自动工具会删除该字段并添加一个新字段,从而丢失内容。

于 2010-04-20T09:59:50.697 回答