JPA OneToMany Association from superClass

会有一股神秘感。 提交于 2019-11-30 15:49:06

Choose your type of superclass according to your needs:

Concrete Class

public class SomeClass {}

Define your superclass as a concrete class, when you want to query it and when you use a new operator for further logic. You will always be able to persist it directly. In the discriminator column this entity has it's own name. When querying it, it returns just instances of itself and no subclasses.

Abstract Class

public abstract class SomeClass {}

Define your superclass as an abstract class when you want to query it, but don't actually use a new operator, because all logic handled is done by it's subclasses. Those classes are usually persisted by its subclasses but can still be persisted directly. U can predefine abstract methods which any subclass will have to implement (almost like an interface). In the discriminator column this entity won't have a name. When querying it, it returns itself with all subclasses, but without the additional defined information of those.

MappedSuperclass

@MappedSuperclass public abstract class SomeClass {}

A superclass with the interface @MappedSuperclass cannot be queried. It provides predefined logic to all it's subclasses. This acts just like an interface. You won't be able to persist a mapped superclass.

For further information: JavaEE 7 - Entity Inheritance Tutorial


Original message

Your SuperClass LendingLine needs to define a @DiscriminatorValue as well, since it can be instantiated and u use an existing db-sheme, where this should be defined.

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