I am using Hibernate 6.2 on an Oracle DB in a Jakarta EE application. I have a few main entities and each of them have an onetomany association towards another entity which holds the descriptions in different languages for objects of this entity. I would like to define a superclass that will hold a generic description type of entity T and modify the onetomany and manytoone associations accordingly. So far I have the generic class
@MappedSuperclass
public abstract class Description<T> {
@Column(name = "DESCRIPTION", nullable = false)
private String description;
@Embedded
private DescriptionToDescribableRelation<T> embeddedParent;
...
The embedded relation between the parent entity and its description entity
@Embeddable
public class DescriptionToDescribableRelation<T extends ThingT> {
@ManyToOne(fetch = FetchType.LAZY, optional = false)
private T describable;
public DescriptionToDescribableRelation(T describable) {
this.describable = describable;
}
An example of a specific description entity
@Entity
@Table(name = "FOO_DESCRIPTION")
public class FooDescription extends Description<Foo> {
@Embedded
@AttributeOverride(name = "describable", column = @Column(name = "FOO_ID", nullable = false))
private DescriptionToDescribableRelation<Foo> embeddedParent;
and finally the parent entity of the above description
@Entity
@Table(name = "FOO")
public class Foo {
@Id
@Column(name = "FOO_ID", nullable = false)
private Integer fooId;
@OneToMany(mappedBy = "embeddedParent.describable")
private Set<FooDescription> fooDescrs = new HashSet<>();
Unfortunately when I am trying to fetch either Foo or FooDescrs like this select f from FooDescription f I am getting an incorrect sql from Hibernate. The sql I am getting is this select c1_0.describable_FOO_ID (.. other fields) from FOO_DESCRIPTION c1_0. I do not understand why is this column name being resolved instead of the one I specified in the AttributeOverride. Are there alternatives with a similar effect that I might have missed?
Thank you in advance.