I need association OneToMany from Country to superclass Place. It could be bidirectional. But Place is MappedSuperclass.
I would need something like @OneToAny but this type of association doesn't exist.
Superclass Place is ok, I think.
Code:
@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;
}
}
Country:
Code:
@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") // if this, in table country I have field "unnecessary"
// @OneToMany(mappedBy="country") // if this, NullPointerException...
public List<Place> getPlaces() {
return places;
}
public void setPlaces(List<Place> places) {
this.places = places;
}
@Column
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Column
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
}
Please for help.