Java /JPA | Query with specified inherited type

后端 未结 4 1838
野的像风
野的像风 2020-12-10 13:23

I am building a query on a generic table \"Sample\" and I have several types which inherit from this table \"SampleOne\", \"SampleTwo\". I require a query like :

         


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-10 13:58

    In JPA 2.0 you can use TYPE expression (though currently it doesn't work with parameters in Hibernate, see HHH-5282):

    select s from Sample s where TYPE(s) = :type
    

    The similar Hibernate-specific expression is .class:

    select s from Sample s where s.class = :type
    

提交回复
热议问题