我需要@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(s):tour.spring.bc.model.vo.Country.places
在表 City 和 Region 中,表 Country (Region.country_id, City.country_id) 的外键是可以的。但是我不需要表 Country 到表 Region 和 City 中的外键,所以我不需要@JoinColum
.
我能做些什么?