问题标签 [discriminator]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
hibernate - JPA (Hibernate) SINGLE_TABLE 继承包罗万象的鉴别器值?
我正在映射一个遗留数据库,其中一个表使用SINGLE_TABLE
使用鉴别器列的映射自然地映射到继承层次结构。问题是有大量的鉴别器值!(此外,偶尔会添加新的,应用程序应该在多态查询中自动选择它们)。从我的应用程序的角度来看,我想以相同的方式对待绝大多数这些不同类型(即,只需将它们映射到继承层次结构中的基类)。但是,对于少数人,我想映射到特定的子类。问题是 JPA 似乎要求我在基类上提供一个特定@DiscriminatorValue
的(否则它会生成一个默认的)。
具体来说:
有没有办法在 JPA(或 Hibernate 3.3 特定的扩展)中优雅地映射它?我能想到的唯一解决方案是放弃继承并将列映射为一个普通字段,在内部为特殊情况切换该值,但这感觉不自然而且有点脏。
xml - NHibernate 映射到现有数据库模式:不知道具体如何解决?
情况如下:
我有一个 Oracle 数据库,其中给出了数据库模式,所以我无法更改它。ID 是通过数据库生成的,是主键。OR-mapper 是一个自写的,我必须用 NHibernate 替换它。
我有两个表,它们只有一个关联,没有继承:
- 模式类型:ID、名称、来源
- 模式:ID、Mode_Type_ID、评论
我的课程如下:
- ModeType:公共属性:ID、名称、来源
- ModeProduction:公共属性:ID、ModeType_ID、评论
- ModeQualityCheck:公共属性:ID、ModeType_ID、评论
使用“旧” OR-mapper 类ModeProduction和ModeQualityCheck被持久化到表Mode中。例如,您要检索(然后写回)所有ModeProducts,ModeProducts取自表Mode,其中“ModeType_ID”等于“Origin” = 1的ModeType表中的“ID”。属性/列“起源”就像一个鉴别器,但没有继承。
那么,我如何在 NHibernate 中映射它以获得相同的效果:获取所有ModeProducts(并稍后将它们写回),其中ModeType表中的 Origin 为 1?
到目前为止,我有以下 XML 映射:
模式类型:
ModeProduction: (Origin = 1 in table ModeType )
ModeQualityCheck:(表ModeType中的Origin = 0 )
有人可以帮帮我吗?
hibernate - 如何处理 org.springframework.orm.hibernate3.HibernateObjectRetrievalFailureException 与单表继承?
我正在使用 JPA Discriminator 注释和单表继承策略和 Hibernate ORM 实现来处理我的应用程序中的不同用户类型。当数据中存在未知的鉴别器值时,Hibernate 会抛出如下异常:
是否有 JPA 方式/注释来忽略未知的鉴别器值?
谢谢,
汤姆
php - 带有 Doctrine2 的连接表中的鉴别器
我有一个名为 Divers 的抽象父类,它由几个其他类扩展。
因此,我使用单表继承策略将继承映射与 D2 一起使用。
我想要实现的是在浏览器中显示鉴别器,并带有一点描述,向用户解释它是什么。
我搜索了一个解决方案,比如将鉴别器放在一个连接表中,但什么也没找到。
你对实现我的目标有什么建议吗?
提前感谢您的帮助。
java - Hibernate Discriminator
I have something like that
resource_type and resource_id are used to discriminate type of resource:
resource_type can be image
or video
, if resource_type contains image
resource_id is id of the table IMAGE; if resource_type contains video
resource_id is id of the table VIDEO
here IMAGE and VIDEO tables
(*) tables are more complicated, but for better explanation I shrank it!!!
I have the following class, too
i tried to understand something about discriminator attribute from this tutorial: http://viralpatel.net/blogs/hibernate-inheritence-table-per-hierarchy-mapping/ but example is little bit diffenet...-_-'
I want map IMAGE end VIDEO table in Resource object of Action class,how I can map these pojo classes with hibernate xml mapper???
entity-framework - Advanced TPH Mapping to Legacy Database
I have been working on a project in which I am trying to mold entity framework to an existing FoxPro 2.x database in order to use the data while leaving the tables readable to a legacy application (more details on my previous question).
I've had pretty good luck configuring the DBContext
to the physical data tables and I have most of my mapping set up. The legacy data structure has a Bills
table with a unique primary Id key, but all the LineItems
that can be posted to a bill are stored in a single Charges
table without a simple primary key.
My question pertains to discriminator mapping in code-first EF. I am recreating the table as TPH in my data objects, so I have
where my mapping strategy so far is along these lines:
I have omitted some fields and mapping classes, but this is the core of it.
Every record has the C/P classification, so this makes everything in the table either a Charge
or a Payment
.
Every Posting
is associated with a Bill
via Bill_Num
foreign key.
The ServiceLine
object is only distinct from ChargeVoid
objects (which are adjustment entries and no-value information entries associated with a bill) by having values for Pcode
and Chargeid
(which is just Bill_Num
tagged with 01
++). I have no idea how to model this.
It is very similar for the Payment
hierarchy as well.
So with my current setup, I have Postings
which doesn't have a unique key, Charges
which has a subset of ServiceLines
with values for Chargeid
and Pcode
and a subset with null
s, and Payments
similar to Charges
. PaymentLines
are also many-to-one with ServiceLines
by way of Pcode
while PaymentVoids
have Pcode = null
.
Is there a way I can assign this complex mapping since I can't simply discriminate on !null
? On top of that, will EF handle the key assignments once I get the inheritance set up, or am I going to have issues there as well?
Also, if there is a better way to break this object inheritance down, I am all ears.
java - Hibernate DiscriminatorColumn.Type 不起作用
我有一个抽象类 AbstractTile
以及许多继承自 AbstractTile 的类
问题是当我想将它们保存到数据库中时,它有错误
我究竟做错了什么?DiscriminatorType 设置为 String 那么为什么它需要 int 呢?
编辑:SQL 创建语句
entity-framework - EF Code first TPH,类型更改时不更新鉴别器列
我正在学习实体框架并在删除记录时与 TPH 作斗争。我创建了如下 POCO
在我的 DbContext 中,我重写了 OnModelCreating 方法。我在那里有以下代码。
我已经编写了插入和更新事务的代码。插入工作正常。它使用 paymentDetail(作为现金)创建交易。但是当我更新它并将 PaymentDetail 更改为 BankTransfer 时,它会更新 PaymentDetail 中的详细信息(这是一个作为 TPH 创建的平面表)。但它不会更改鉴别器列。它仍然是 Cash,因为它最初是使用 Cash 类型创建的。我通过谷歌搜索发现鉴别器列没有改变。所以我试图删除该行,但它现在给出了以下错误
DELETE 语句与 REFERENCE 约束“FK_dbo.Transaction_dbo.PaymentDetail_PaymentDetail_Id”冲突。冲突发生在数据库“MyRecordsDB”、表“dbo.Transaction”、列“PaymentDetail_Id”中。该语句已终止。
EF代码创建的TransactionTable首先有PaymentDetail_ID可以有allow null,那么谁能告诉我这个问题吗?
在这种情况下使用 TPH 好不好?
以下是从我的 RepositoryClass 修改 Transaction 的方法供参考。
symfony - 教义类表继承得到所有孩子
我想获取所有文章,并获取文章的类型(判别器)。也许还有另一种方法可以组合所有孩子(所有固定和拍卖的记录)并在创建日期对它们进行排序?
文章实体:
拍卖实体
固定实体
c# - Asp.net Identity - 如何登录,无论鉴别器如何
我使用 asp.net 身份,并且我有许多从 IdentityUser 继承的用户类。
假设我有一个继承链,例如:
IdentityUser <- AppUser <- ServiceUser <- ServiceEmployee 和 ServiceCustomer(它们都继承自 ServiceUser)。
尝试创建统一的登录表单时,最好的策略是什么?
如果您使用 OTB 帐户控制器并将 UserManager 更改为使用 ServiceUser 但尝试登录注册为 ServiceEmployee 的帐户,它将失败,因为 FindAsync() 显然仅尝试基于鉴别器字段中的“ServiceEmployee”进行查找,所以如果帐户被注册为不同的“类型”,它不能用于登录。因此,当注册类型与登录类型不同时,任何组合都会发生这种情况。
我是否应该更新登录操作以使用多个 UserManager,以便检查每种用户类型,或者是否有更好的方法来实现我想要实现的目标。
感谢您提供任何信息。