Table per subclass inheritance relationship: How to query against the Parent class without loading any subclass ??? (Hibernate)

后端 未结 3 889
感动是毒
感动是毒 2020-12-05 08:57

Suppose a Table per subclass inheritance relationship which can be described bellow (From wikibooks.org - see here)

Notice Parent class is n

3条回答
  •  我在风中等你
    2020-12-05 09:25

    Actually, there is a way to get just the superclass, you just need to use the native query from JPA, in my case I'm using JPA Repositories it would be something like that:

    @Query(value = "SELECT * FROM project", nativeQuery = true)
    List findAllProject();
    

    The flag nativeQuery as true allow running the native SQL on database.

    If you are using Entity Manager check this out: https://www.thoughts-on-java.org/jpa-native-queries/

提交回复
热议问题