将POJO映射到实体 [英] Mapping POJO to Entities

查看:116
本文介绍了将POJO映射到实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的项目中,我们有一个约束,那就是不能奢侈地更改已经存在的表结构.这些表实际上是高度非规范化的.

In our project we have a constraint of not having the luxury to alter the table structure already in place. The tables are highly denormalized in nature.

我们为该应用程序提供了很好的POJO.我们从现有表中生成了Entity Bean.现在我们必须将POJO映射到实体,以便我们可以持久化.

We have come up with good POJOs for the application. We have the Entity beans generated out of the exiting tables. Now we have to map the POJOs to the entities so that we can persist.

最终,我们将一个好的POJO与一个坏的表相结合.对这种方法的选择/替代方案/建议有何想法?

Ultimately, we combine a good POJO with a bad table. Any thoughts on options/alternatives/suggestions to this approach?

推荐答案

Hibernate/JPA(2)具有一组丰富的功能来操纵映射(以便您的对象可以与表不同),因此很多(不ALL)旧表可以映射到普通对象. -也许您应该先看看一下,只有在此映射功能不够强大的情况下,才可以使用pojo/table-"solution".

Hibernate/JPA(2) has a rich set of functionality to manipulate the mapping (so that your objects can differ from the tables), so that many (NOT ALL) old tables can be mapped to normal object. -- May you should have a look at this first, any use your pojo/table-"solution" only if this mapping is not powerful enough.

如果您具有只读应用程序,则可以考虑使用视图使表更像对象.这可能会减少大量奇怪的映射.

If you have a read only application, you can think of using views to make your table/views more like you objects. This may reduse the amount of strange mapping.

我不知道您的映射,应用程序大小或用例,但是您是否考虑过不使用Hibernate?我问这个问题,是因为我可以想象(我怎么说:我不认识您的应用程序),在这样的体系结构中,没有使用Hibernate功能,因此Hibernate将只添加一个不需要的功能.复杂性.

I don't know your mapping, size of the application or use case, but have you considered not to use Hibernate? I ask this, because I can imagine (how I said: I don't know you application), that in a architecture like this, no Hibernate feature is used and so Hibernate will add only a not needed complexity.

这篇关于将POJO映射到实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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