there is a way to return a custom object with a criteria query or hql query?
For example, i have a class MyClass with a constructor MyClass(int id, String text), i want incapsulate my queries result in this class:
"select new MyClass(e.id, e.name) from Example e"
MyClass is not an entity, but a simple custom class.
Thank all.
In HQL queries it works exactly as you showed (class name should be fully qualified, i.e. with package).
Although, as far as I understand, it’s not supported in Hibernate Criteria API, but supported in JPA 2.0 Criteria API as
CriteriaBuilder.construct().