gpt4 book ai didi

java - 如何从 Hibernate 的 @Any 中的值计算 @MetaValue 的 entityTarget?

转载 作者:行者123 更新时间:2023-12-04 05:53:42 29 4
gpt4 key购买 nike

我已经实现了类似于以下内容的解决方案:
How to use Hibernate @Any-related annotations? ,而且它已经失控了 - 我有太多具有类似映射“方案”的映射:

@Any(metaColumn = @Column(name = "something_type"), fetch = FetchType.LAZY)
@AnyMetaDef(idType = "long", metaType = "string", metaValues = {
@MetaValue(value = "A", targetEntity = AImpl.class),
@MetaValue(value = "B", targetEntity = BImpl.class),
@MetaValue(value = "C", targetEntity = CImpl.class),
@MetaValue(value = "D", targetEntity = DImpl.class),
@MetaValue(value = "E", targetEntity = EImpl.class),
etc.. })
public BaseSomething getRelatedSometing() {
return relatedSometing;
}

我试图保留一个可以计算到目标(例如“AImpl”)的值(例如“A”)。
有没有办法避免手动列出所有实现,但仍然保持 hibernate 状态?

最佳答案

I asked a similar question ,希望得到支持Spring style meta-annotations .

但是,与此同时,以下内容对我来说效果很好:

class SomeClass {
public static final String SOMETHING_METADEF_NAME = "somethingMetadefName";


@Any(metaColumn = @Column(name = "something_type"), fetch = FetchType.LAZY)
@AnyMetaDef(idType = "long", metaType = "string", name=SomeClass.SOMETHING_METADEF_NAME,
metaValues = {
@MetaValue(value = "A", targetEntity = AImpl.class),
@MetaValue(value = "B", targetEntity = BImpl.class),
@MetaValue(value = "C", targetEntity = CImpl.class),
@MetaValue(value = "D", targetEntity = DImpl.class),
@MetaValue(value = "E", targetEntity = EImpl.class),
etc.. })
public BaseSomething getRelatedSometing() {
return relatedSometing;
}
}

// Elsewhere
@Any(metaColumn = @Column(name = "something_type"), fetch = FetchType.LAZY,
metaDef=SomeClass.SOMETHING_METADEF_NAME)
public BaseSomething getAnotherSomething() {
return relatedSometing;
}

具体来说,我定义了一次关系,并给它一个 name属性(property)在 @AnyMetaDef .然后,我可以从 @Any(metaDef=MY_NAME) 中引用它别处。

希望这可以帮助

关于java - 如何从 Hibernate 的 @Any 中的值计算 @MetaValue 的 entityTarget?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9771954/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com