Caller と Employee という 2 つの他のエンティティの親であるエンティティ Person があります。これらのエンティティは、識別子列 person_id を持つ SINGE_TABLE 戦略を使用して実装されます。
また、私は別のエンティティを持っています: Person と ManyToMany 関係を持つ Location です。そのため、1 人の人物が複数の場所に属している場合があり、1 つの場所に複数の人物がいる場合があります。
Location と Person を manyToMany にマップするのは簡単でしたが、今度は子エンティティをマップする方法が必要です。および getCallers();
私は次のようなものを試しました:
public class Location implements Serializable, Comparable<Location> {
private static final long serialVersionUID = 1L;
@ManyToMany(mappedBy="locations")
private List<Caller> callers = new ArrayList<Caller>();
@ManyToMany(mappedBy="locations")
private List<Employee> employees = new ArrayList<Employee>();
}
@Entity
@DiscriminatorValue("0")
@Access(AccessType.FIELD)
public class Caller extends Person {
private static final long serialVersionUID = 1L;
@Column(name = "company_name")
private String companyName;
@Column(name = "individual")
private Boolean individual;
}
@Entity
@Access(AccessType.FIELD)
@DiscriminatorValue("1")
public class Employee extends Person {
private static final long serialVersionUID = 7526471155622776147L;
}
@Entity
@Access(AccessType.FIELD)
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="person_type",discriminatorType=DiscriminatorType.INTEGER)
@Table(name="persons")
public class Person implements Serializable, Comparable<Person>{
private static final long serialVersionUID = 7526471155622776147L;
@ManyToMany
@JoinTable(name="persons_locations",
joinColumns={@JoinColumn(name="person_id")},
inverseJoinColumns={@JoinColumn(name="location_id")})
private List<Location> locations;
}
しかし、アプリをコンパイルしようとすると、次のエラーが発生します。
Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: xxx.entities.yyy.Caller.locations in xxx.vs.entities.yyy.Location.callers.
解決策の 1 つは場所を子に移動することだと思いますが、コードをコピーして貼り付ける必要があります。結局のところ、場所は一般的な人のプロパティです。
この種の問題に対処する適切な方法は何ですか?