Hibernate:在类中使用mappedBy来扩展另一个注解为JoinedSubclass的类? [英] Hibernate: Used mappedBy on class that extends another class annotated as JoinedSubclass?

查看:107
本文介绍了Hibernate:在类中使用mappedBy来扩展另一个注解为JoinedSubclass的类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下行不通:

  @Entity 
类所有者{

@OneToMany(mappedBy =owner,cascade = {CascadeType.ALL})
protected Set< B> getBSet(){
..
}

}

@实体
@Inheritance(strategy = InheritanceType.JOINED)
class A {
@ManyToOne
Public Owner getOwner(){
...
}
}

@实体
class B扩展A {b
$ b}


org.hibernate.AnnotationException:mappedBy引用未知目标实体属性:B.user in Owner。



我试图避免复制owner属性转换为B类(这将因此非规范化并将所有者密钥复制到为实体A和B生成的两个表中)。另外,我真的希望将A和B放在单独的表中,而不必使用SingleTable继承来使用鉴别器。



另外,我无法弄清楚如何在A和B之间使用@OneToOne来做类似的事情(而不是让B扩展A)。奇怪,但它是故意的。我有博文和背景信息,链接和JOINED解决方案的解决方法。


The following doesn't work:

@Entity
class Owner {

  @OneToMany(mappedBy="owner", cascade = {CascadeType.ALL})
  protected Set<B> getBSet() {
    ..
  }

}

@Entity
@Inheritance(strategy=InheritanceType.JOINED)
class A {
   @ManyToOne
   public Owner getOwner() {
     ...
   }
}

@Entity
class B extends A {

}

It causes an exception as such: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: B.user in Owner.

I am trying to avoid copying the "owner" property into class B (which will consequently "denormalize" and copy the owner key into both tables generated for entity A and B). Also, I would really like to have A and B in a separate table and not have to use a discriminator by using SingleTable inheritance.

Also, I can't figure out how to do something similar by using @OneToOne between A and B (and not having B extend A).

解决方案

It's a Hibernate oddity, but it's deliberate. I have a blog post up with background information, links and a workaround for the JOINED solution.

这篇关于Hibernate:在类中使用mappedBy来扩展另一个注解为JoinedSubclass的类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆