Why is my subquery returning only the ID and not the full entity?

I’m encountering an issue, and I’m using the following as a test example. The subquery is expected to return a full Person entity, but instead, it’s only returning the ID. Here’s a simplified version of the query:

TypedQuery<Object> query = entityManager.createQuery("SELECT pe, (SELECT pe1 FROM Person pe1 WHERE pe1.nm = pe.nm AND pe1.active = true) " +
“FROM Person pe”, Object.class);

In the result, the subquery (pe1) only includes the ID instead of the full Person object. This used to work as expected in Hibernate 4.3, where the subquery returned the complete object. Any ideas on what might be causing this behavior in the current version?

This might have worked in previous Hibernate versions by accident, but is generally not supported. It’s easy to rewrite the query to a supported form:

select pe, pe2
from Person pe
left join Person pe2 on pe.nm=pe2.nm and pe2.active

Thanks you very much!!