0

我想知道是否存在概念框架或记录技术来研究如何将实体类映射到数据库表?

在我使用 JPA(Java Persistance API)映射一个表 -> 一个实体类之前,这是:每个表的行由一个对象类表示。这是最常见/正确的方法吗?这些模式有特定的名称吗?

非常感谢。

4

2 回答 2

1

One table to one class is called the "Active Record" pattern. One alternative pattern people use is the Repository pattern. DDD (Domain Driven Design) has the concept of Aggregate Roots which also plays in this space. You should be able to do some reading on that terminology. I am personally not in love with any of those patterns, they all have pros and cons.

于 2012-04-24T12:01:45.123 回答
0

对我来说,理想的类与表关系没有配方、公式或模式。映射的关键在于它充当适配器层,将表结构与实体结构隔离开来。如果您同时设计应用程序和表格,我认为您应该设计表格以最大限度地减少往返行程,获取尽可能多的数据来补充您的实体。然后让您的映射器构建实体和任何适当的关联。这可能会导致您对表结构的非规范化程度比通常情况下要多一些。

于 2012-04-23T19:40:18.317 回答