I have have a question about how should we work with db in JPA manner when dealing with translated tables.
So, let’s assume that I have next entities:
class A {
@Id
@Column(name = "id", nullable = false)
private UUID id;
@OneToMany(mappedBy = "a")
private Set<B> bSet = new HashSet<>();
@OneToMany(mappedBy = "a")
private Set<ATranslation> translations = new HashSet<>();
\ getters and setters
}
class ATranslation {
@Id
@Column(name = "id", nullable = false)
private UUID id;
@ManyToOne()
@JoinColumn(name = "a_id", nullable = false)
private A a;
@Column(name = "language_code")
private String languageCode;
@Column(name = "is_default")
private Boolean isDefault = Boolean.FALSE;
// Other specific fields (for example: name, title and e.t.c)
}
Class B has also own translation with specific fileds. So How can I deal with this structure? Foe example I want to get A by id with all B for specific language request and if translation for specified language does not exist I want to retreave default language. How can achive it?
Also assume that dto which I should return should looks like something this:
clas ADto {
private UUID id;
private String title;
private String name;
private Set<BDto> bDtoSet = new LinkedHashSet<>();
}