Java /JPA | Query with specified inherited type

后端 未结 4 1841
野的像风
野的像风 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:48

    You still have to be carefull in Hibernate 4.3.7, because there is still an issue with the implementation of TYPE(), for example:

    from SpoForeignPilot sfp where TYPE(sfp.partDocument) = :type
    

    This query doesn't work as it incorrectly checks the type of SpoForeignPilot and not the type of the document.

    You can workaround this issue by doing something like this:

    select sfp from SpoForeignPilot sfp join sfp.partDocument doc where TYPE(doc) = :type
    

提交回复
热议问题