How to perform a non-polymorphic HQL query in Hibernate?

后端 未结 5 768
面向向阳花
面向向阳花 2020-11-30 05:43

I\'m using Hibernate 3.1.1, and in particular, I\'m using HQL queries.

According to the documentation, Hibernate\'s queries are polymorphic:

A

5条回答
  •  [愿得一人]
    2020-11-30 06:33

    The ORM mimics the Java Model: if an object is an instance of another type (if an instance of PersianCat is an instance of Cat also), any query on Cat will have to be polymorphic (imagine you querying a List and asking if the entries match instanceof Cat.

    Even Bozho's solution is somewhat impure, since the 'class' column is supposedly opaque to your hibernate mapping, although I admit its a very good compromise. You can simply get the discriminator through the classe's simple name.

    If you're comfy and are using table per class you can always do a native query to the Cat table to get the ids and then get the entries through hibernate.

提交回复
热议问题