gpt4 book ai didi

java - 不使用注解参数的Hibernate接口(interface)映射 "targetEntity"

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:34:33 24 4
gpt4 key购买 nike

我最近试图为我的一些 hibernate 映射实体引入接口(interface),但不知道如何配置映射。

当我在没有任何进一步声明的情况下使用接口(interface)时,我总是得到以下异常:

org.hibernate.MappingException: Could not determine type for: ...MyInterface 

然后当我明确定义 targetEntity 时,我发现一切正常:

   @OneToOne(targetEntity=InterfaceImpl.class)
private MyInterface myInterface;

不幸的是,这个解决方案在我的情况下不起作用:我无法通过注释定义 targetEntity,因为我想将此类提取到一个不包含甚至不知道接口(interface)的最终实现的公共(public)外部库。

那么是否有另一种方法来声明应该使用哪个实现,我可以在提取的库之外使用? enter image description here

最佳答案

在抽象@MappedSupperclass 中定义您的映射契约,然后在实现类中用@AssociationOverride 覆盖它。

关于java - 不使用注解参数的Hibernate接口(interface)映射 "targetEntity",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15273553/

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