开发者

Hibernate Subclass which has multiple discriminator values

Hello I have a Subclass which needs to cover multiple Discrimina开发者_Go百科tor Values.

something like:

@DiscriminatorValue(value = "ACT","DNR","ATT" )

would do me perfect.

we have existing data where several discriminators can be mapped to one class (as they are similar types of what our system will consider the same thing)


You can use DiscriminatorFormula:

// Base class
@DiscriminatorFormula("case when value in ('ACT','DNR','ATT') then 1 
   when 'OTH' then 2 else 3 end")

// Subclass 
@DiscriminatorValue("1") // maps to ACT, DNR, ATT


A subclass has exactly 1 discriminator value.

You can add additional subclasses under the existing subclass for the extra discriminator values. Subclasses need not have additional properties or behavior.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜