JPA 2.1 NamedSubgraph in Hibernate ignores subclasses

I use Hibernate 4.3.8.FINAL and have the following model, in which the Department has many Workers, and the Employee can be a Manager.

The essence of the employee:

@Entity
@Table(name = "employee", schema = "payroll")
@Inheritance(strategy = InheritanceType.JOINED)
public class Employee
{
    @Id
    private Long id;

    @Basic(optional = false)
    @Column(name = "name")
    private String name;

    @JoinColumn(name = "department_id", referencedColumnName = "id")
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Department department;
}

Manager Essence:

@Entity
@Table(name = "manager", schema = "payroll")
@Inheritance(strategy = InheritanceType.JOINED)
@PrimaryKeyJoinColumn(name = "employee_id", referencedColumnName = "id")
public class Manager extends Employee
{
    @Basic(optional = false)
    @Column(name = "car_allowance")
    private boolean carAllowance;
}

The essence of the unit:

@NamedEntityGraph(
        name = "Graph.Department.FetchManagers",
        includeAllAttributes = false,
        attributeNodes = {
                @NamedAttributeNode(value = "name"),
                @NamedAttributeNode(value = "employees", subgraph = "FetchManagers.Subgraph.Managers")
        },
        subgraphs = {
                @NamedSubgraph(
                        name = "FetchManagers.Subgraph.Managers",
                        type = Employee.class,
                        attributeNodes = {
                                @NamedAttributeNode(value = "name")
                        }
                ),
                @NamedSubgraph(
                        name = "FetchManagers.Subgraph.Managers",
                        type = Manager.class,
                        attributeNodes = {
                                @NamedAttributeNode(value = "carAllowance"),
                        }
                )
        }
)
@Entity
@Table(name = "department", schema = "payroll")
public class Department
{

    @Id
    private Long id;

    @Basic(optional = false)
    @Column(name = "name")
    private String name;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "department", fetch = FetchType.LAZY)
    private Set<Employee> employees;
}

As shown in the entity of the unit, I am trying to create @NamedSubgraph, which downloads all employees and also retrieves Manager.carAllowance. However, I get the following error:

Unable to locate Attribute  with the the given name [carAllowance] on this ManagedType [com.nemea.hydra.model.test.Employee]

From my point of view, @ NamedSubgraph.type should be used to indicate the attributes of the subclass of the object to be extracted. Is it possible that Hibernate is ignoring the type = Manager.class attribute of the @NamedSubgraph annotation, or am I missing something?

+4
1

Hibernate 4.3.8.FINAL, . EclipseLink 2.5.1 , subgraphs.

, subclassSubgraphs, subclass Manager, :

@NamedEntityGraph(
    name = "Graph.Department.FetchManagers", 
    includeAllAttributes = false,
    attributeNodes = {
        @NamedAttributeNode(value = "name"),
        @NamedAttributeNode(value = "employees", subgraph = "FetchManagers.Subgraph.Managers")
    },
    subgraphs = {
        @NamedSubgraph(
            name = "FetchManagers.Subgraph.Managers",
            type = Employee.class,
            attributeNodes = {
                @NamedAttributeNode(value = "name")
            }
        )
    },
    subclassSubgraphs = {
        @NamedSubgraph(
            name = "FetchManagers.Subgraph.Managers",
            type = Manager.class,
            attributeNodes = {
                @NamedAttributeNode(value = "carAllowance"),
            }
        )
    }
)
+4

All Articles