@OneToMany
Country からスーパークラスPlace
( ) への関連付けが必要@MappedSuperclass
です。双方向である可能性があります。のようなものが必要です@OneToAny
。
@MappedSuperclass
public class Place {
private String name;
private Country country;
@Column
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@ManyToOne
@JoinColumn(name="country_id")
public Country getCountry() {
return country;
}
public void setCountry(Country country) {
this.country = country;
}
}
国:
@Entity
public class Country {
private long id;
private String name;
private List<Place> places;
@Any(metaColumn = @Column(name = "place_type"), fetch = FetchType.EAGER)
@AnyMetaDef(idType = "integer", metaType = "string", metaValues = {
@MetaValue(value = "C", targetEntity = City.class),
@MetaValue(value = "R", targetEntity = Region.class) })
@Cascade({ org.hibernate.annotations.CascadeType.ALL })
//@JoinColumn(name="unnecessary")
//@OneToMany(mappedBy="country") // if this, NullPointerException...
public List<Place> getPlaces() {
return places;
}
//and rest of class
例外@JoinColunm
はありません:
原因: org.hibernate.AnnotationException: @Any には明示的な @JoinColumn が必要です: tour.spring.bc.model.vo.Country.places
テーブル City と Region はテーブル Country (Region.country_id, City.country_id) への外部キーであり、これは問題ありません。しかし、テーブルRegionとCityへのテーブルCountryには外部キーは必要ないので、必要ありません@JoinColum
。
私に何ができる?