Criteria query to load rows for a class type which is not mapped to a single table/entity in Hibernate
Issue
Load arbitrary "tuples" from entity class properties into a custom "tuple" class using a criteria query given the following:
public static class EmpDepTuple { // custom non-entity tuple class
private String emp, dep;
public EmpDepTuple(String emp, String dep) {
this.emp = emp;
this.dep = dep;
}
public String getEmp() {
return emp;
}
public String getDep() {
return dep;
}
}
@Entity
public class Department {
private String name;
}
@Entity
public class Employee {
private String name;
private Department department;
}
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 5
- 6
- Hibernate Native/JPA
- 3
- 4
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
