Selecting MappedSuperclass from the database (Hibernate)

前端 未结 3 886
醉酒成梦
醉酒成梦 2021-01-01 23:40

Problem

I have a @MappedSuperclass called Data as the parent of every Entity in my database. It contains common attributes like Id etc. I then have an

3条回答
  •  长情又很酷
    2021-01-02 00:11

    No if you are using @MappedSuperclass

    The reason for this is that when you define base class as @MappedSuperclass, there is no table generated for the base class, instead all of the properties are replicated in the concrete tables. In your example only FullTimeEmployee, PartTimeEmployee and Store tables would exist.

    If you want to be able to query for base class entities you need to select different mapping for base classes. Use @Inheritance annotation on the base class and select one of the 3 possible mapping strategies - SINGLE TABLE, TABLE PER CLASS or JOINED

提交回复
热议问题