Named query on a Mapped Superclass

旧时模样 提交于 2019-12-01 13:02:44

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.

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