域对象与JPA实体相同吗? [英] Are domain objects the same as JPA entities?

查看:98
本文介绍了域对象与JPA实体相同吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

域对象是否与JPA实体相同?如果我有一个价值对象(例如一美元的钞票),我如何(甚至应该)将其作为参考对象存储在数据存储中?

Are domain objects the same as JPA entities? If I have a value object (e.g. a dollar bill), how can I (or even should I) store that in the datastore as a reference object?

在某些情况下,域对象是实体,在某些情况下是值对象的微妙之处是什么?有人可以指导我写一篇好论文吗?

What are the subtleties of domain objects being entities in some cases and value objects in other cases? Could anyone direct me to a good paper on this?

推荐答案

域对象"是一个更具概念性的术语; "JPA实体"是指对实现域对象有用的特定技术.

"Domain object" is a more conceptual term; "JPA entity" refers to a specific technology useful for implementing domain objects.

通常,领域对象与您领域中的名词(订单,发票,客户等)相对应.通常,我们认为这些对象更接近数据库,而不是纯数据传输对象.因此,例如,您可能会在用于实现域对象的类上看到ORM注释.

Generally domain objects correspond to the nouns (orders, invoices, customers, etc.) in your domain. Usually we see these as being closer to the database rather than pure data transfer objects. So you might see ORM annotations on the classes you use to implement your domain objects, for example.

许多人以贫乏的方式实现域对象-大多数是带有ORM映射的属性,但是域对象本身没有真正的逻辑.他们将逻辑放在域服务中.

A lot of people implement domain objects in an anemic way--mostly properties with ORM mappings, but no real logic on the domain objects themselves. They put the logic in domain services.

另一方面,领域驱动设计的支持者将逻辑放在领域对象上.

On the other hand proponents of domain-driven design put the logic on the domain objects.

无论哪种方式,这些都是系统中的域对象.

Either way these are the domain objects in your system.

JPA实体是您用@ Entity,@ Column,@ ManyToOne等进行注释的类.这是一种实现域对象的方法.如上所述,您可以决定将域逻辑放在对象本身上.

JPA entities are classes that you annotate with @Entity, @Column, @ManyToOne, etc. This is a way to implement domain objects. You may decide to put domain logic on the objects themselves, as noted above.

这篇关于域对象与JPA实体相同吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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