开发者

Hibernate Subclass which has multiple discriminator values

开发者 https://www.devze.com 2022-12-22 16:15 出处:网络
Hello I have a Subclass which needs to cover multiple Discrimina开发者_Go百科tor Values. something like:

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

精彩评论

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