Named query on a Mapped Superclass

后端 未结 1 1453
暖寄归人
暖寄归人 2021-01-16 02:15

I\'m trying to declare a NamedQuery on a mapped superclass, but I obtain this error:

org.hibernate.hql.ast.QuerySyntaxException: VoipCall is not mappe

1条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-16 02:15

    It is perfectly fine to have @NameQuery annotation in @MappedSuperClass. In past Hibernate used to had issue HHH-4364, which caused this to fail. Issue is fixed since years.

    On the other hand query itself is not expected to work, because mapped superclass cannot be queried. In JPA 2.0 specification this is told with following words:

    A mapped superclass, unlike an entity, is not queryable and must not be passed as an argument to EntityManager or Query operations.

    This restriction kind of makes sense - purpose of mapped superclass is to share mappings between otherwise non-related entities, mapped superclass is not supposed to be root of the entity inheritance hierarchy. If such a query works, it is purely because of JPA vendor specific extension.

    0 讨论(0)
提交回复
热议问题