Hibernate @Embeddable class which extends another @Embeddable class, Properties not found for @OneToMany mapping

橙三吉。 提交于 2019-11-30 17:29:17

You can implement inheritance between @Embeddable classes. You just have to annotate the parent class with @MappedSuperclass too.

So, e.g.:

@Embeddable
@MappedSuperclass
public class Parent {
    @Basic
    private String parentProperty;

    // ... getters/setters
}

@Embeddable
public class Child extends Parent {
    @Basic
    private String childProperty;

    // ... getters/setters
}

This way Hibernate (tested with 5.x) will map both parentProperty and childProperty correctly in the Child class.

Saif

Hibernate doesn't support inheritance of @Embeddable component:

An embeddable object cannot be directly persisted, or queried, it can only be persisted or queried in the context of its parent. An embeddable object does not have an id or table. The JPA spec does not support embeddable objects having inheritance, although some JPA providers may allow this.

Java_Persistence/Embeddables.

The JPA spec does not support embeddable objects having inheritance
So you cannot make use of Inheritance in @Embeddable.

You can try to get it done by having the parent id as a property of the child id.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!