I'm developing a multi language application and My tables are designed for this purpose as well. for example I have a Country class like this:
@Entity
@Table(name = "province")
public class Province {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@ManyToOne
@JoinColumn(name = "country_id", nullable = false)
private Country country;
@OneToMany
@JoinColumn(name = "province_id")
private List<ProvinceTranslation> translations;
}
@Entity
@Table(name = "province_translation")
public class ProvinceTranslation {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
private Language language;
@ManyToOne
@JoinColumn(name = "province_id")
private Province province;
}
I want that translations
field load only translation with specified language, and country field load translation with specified language too(Country
class has a list of CountryTranslation
obviously!). I don't want to write queries and I want that spring data jpa load relations with the language that I specify explicitly.