HHH-12716 - Sample code is required for documentation of disabling polymorphism in queries

This commit is contained in:
Vlad Mihalcea 2018-07-03 14:50:01 +03:00
parent 4a9afdb8c7
commit 569a4e08ca
1 changed files with 9 additions and 3 deletions

View File

@ -968,14 +968,20 @@ include::{sourcedir}/HQLTest.java[tags=hql-polymorphism-example, indent=0]
This query names the `Payment` entity explicitly.
However, all subclasses of `Payment` are also available to the query.
So if the `CreditCardPayment` and `WireTransferPayment` entities extend the `Payment` class, all three types would be available to the entity query,
So, if the `CreditCardPayment` and `WireTransferPayment` entities extend the `Payment` class, all three types would be available to the entity query,
and the query would return instances of all three.
This behavior can be altered in two ways:
- by limiting the query to select only from the subclass entity
- by using either the `org.hibernate.annotations.Polymorphism` annotation (global, and Hibernate-specific). See the <<chapters/domain/inheritance.adoc#entity-inheritance-polymorphism, `@Polymorphism` section for more info about this use case>>.
[NOTE]
====
This can be altered by using either the `org.hibernate.annotations.Polymorphism` annotation (global, and Hibernate-specific) or limiting them using in the query itself using an entity type expression.
The HQL query `from java.lang.Object` is totally valid (although not very practical from a performance perspetive)!
The HQL query `from java.lang.Object` is totally valid! It returns every object of every type defined in your application.
It returns every object of every entity type defined by your application mappings.
====
[[hql-expressions]]