JPA多个鉴别器值 [英] JPA multiple discriminator values

查看:146
本文介绍了JPA多个鉴别器值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在建立一个新项目,并决定将eclipselink用于JPA.在创建领域模型时,我们遇到了一个问题.

We're setting up a new project and decided to use eclipselink for JPA. When creating our domain model we ran into a problem.

我们有一个称为组织"的基类.我们也有供应商和客户,它们都可以扩展组织.当JPA创建表时,我看到它使用了一个区分符,问题在于供应商也可以是组织.

We have a base class called organisation. We also have Supplier and Customer which both extend organisation. When JPA created the tables I saw that it uses a discriminator, the problem with this is that a supplier can also be a organisation.

所以我基本上想要的是(这些数据库表可以帮助您了解这个想法):

So what I basically want is (these are database tables to get the idea):

一个有助于阐明这一点的小例子:

A little example to help clarify this:

我们有一个名为SparklingGlass的客户. SparklingGlass向我们购买了计算机,因此SparklingGlass被保存为我们的客户.我们又从SparklingGlass购买窗户,因此SparklingGlass也是我们的供应商.这就是我们要在系统中实现的.

We have a Customer called SparklingGlass. SparklingGlass buys computers from us so SparklingGlass is saved as our Customer. We in turn buy our windows from SparklingGlass, so SparklingGlass is also our Supplier. This is what we want to realize in our system.

在JPA中这是否有可能,如果不是,那么在这些情况下的最佳实践是什么?

Is this in any way possible in JPA and ifnot, what is the best practice in these cases?

顺便说一句,我们使用JOINED继承类型

BTW we use the JOINED inheritance type

推荐答案

您的数据模型错误.供应商不是组织的子类型,而是组织所扮演的角色.

Your data model is wrong. A Supplier is not a sub-type of Organization but is a Role played by an Organization.

一个组织可以扮演许多角色,例如客户,供应商,供应商,雇主.

An organization can play many roles, such as customer, vendor, supplier, employer.

这篇关于JPA多个鉴别器值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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