"QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list" in Hibernate

Solution In Progress - Updated -

Issue

  • Building a criteria query to execute join fetch for an entity type and its ManyToOne association (e.g. Employee.department -> Department)
  • Filtering the query by properties of the joined type (Department)

    final CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    final CriteriaQuery<Employee> criteria = builder.createQuery(Employee.class);
    
    final Root<Employee> root = criteria.from(Employee.class);
    
    // Create the join fetch to instantiate, in memory, the association between Employee, Department and Manager
    final Fetch<Employee, Department> departmentFetch = root.fetch(Employee_.department, JoinType.INNER);
    departmentFetch.fetch(Department_.manager, JoinType.INNER);
    
    // Create a join to get the path to the joined entity's property
    final Join<Employee, Department> departmentJoin = root.join(Employee_.department, JoinType.INNER);
    
    // Filter against a Department property
    criteria.where(builder.equal(departmentJoin.get(Department_.name), "Support"));
    
    // Execute the query
    entityManager.createQuery(criteria).getResultList();
    
  • The query execution raises

    org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list ...
    
  • The same query executed without raising an exception prior to EAP 6.3.1

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 6.3.1 and later 6.3.x
    • 6.4.0 - 6.4.2
  • Hibernate 4.2.14.SP3

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.