Hi everybody
I have implemented an abstract MappedSuperclass that defines a OneToMany property. I want in subclases to override the "mappedBy" attribute of the OneToMany annotation, so
Code:
@MappedSuperclass
public abstract class BasePersistentObjectTranslateable<T, X extends Translation> extends BasePersistentObject<T> {
@OneToMany()
protected List<X> translations;
public List<X> getTranslations() {
return translations;
}
public void setTranslations(List<X> translations) {
this.translations = translations;
}
}
Code:
@Entity()
@Table(name="Cities")
public class City extends BasePersistentObjectTranslateable<City, CityTranslation> {
// This is the wanted annotation
// @OneToMany(mappedBy="city")
// protected List<CityTranslation> translations;
}
Code:
@MappedSuperclass
public abstract class Translation extends BasePersistentObject<Translation> {
@ManyToOne()
@JoinColumn(name="LanguageId")
protected Language language;
@Column(name="TranslatedText")
protected String translatedText;
/** Creates a new instance of Translation */
public Translation() {
}
public Language getLanguage() {
return language;
}
public void setLanguage(Language language) {
this.language = language;
}
public String getTranslatedText() {
return translatedText;
}
public void setTranslatedText(String translatedText) {
this.translatedText = translatedText;
}
}
Code:
@Entity()
@Table(name="CitiesTranslations")
public class CityTranslation extends Translation {
@ManyToOne()
@JoinColumn(name="CityId")
private City city;
/** Creates a new instance of CityTranslation */
public CityTranslation() {
}
public City getCity() {
return city;
}
public void setCity(City city) {
this.city = city;
}
}
Tha target of all this, is to have the translation of the cities in some languages, so a City or a Country has a collection of translations, and a CityTranslation or a CountryTranslation has a City or a Country, but a CityTranslation has a mappedBy="city" and a CountryTranslation has a mappedBy="country".
Any idea? Thanks in advance.
Hibernate version:3.2.3