I use JPA 2.0 with Hibernate. If I want to select certain columns from the table using CriteriaQuery I have to declare it like this:
CriteriaQuery<Object[]> criteria = cb.createQuery(Object[].class);
Root<Event> root = criteria.from(Event.class);
Path<Long> pid = root.get(Event_.id);
Path<Date> did = root.get(Event_.eventTime);
criteria.select( cb.array(pid, did) );
criteria.where(cb.lessThan(root.get(Event_.id), 10L));
List<Object[]> evs = em.createQuery( criteria ).getResultList();
for ( Object[] ev : evs ) {
System.out.println(ev[0] + " " + ev[1]);
}
So, I am getting an array of chosen properties. But can I in some way get a list of instances of a Event class (in my case) where not selected properites are null ?
Event:
id: 234
typeid: null
eventtime: 12-03-1990
authorid: null
etc...
That was like it when I was using a simple Criteria of Hibernate API.