When a user does not explicitly register a function on the Dialect selected a NullPointerException is thrown without much reason as to why. I would like to suggest handling this problem more gracefully to notify the user of the mistake.
Consider the following:
{code:title=Animal.java|borderStyle=solid} @Entity @Table( name = "ANIMAL" ) public class Animal { private Long id; private Animal mother; private Animal father; private String name; private Date born; } {code}
{code:title=query|borderStyle=solid} CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<HumanPojo> criteria = cb.createQuery( HumanPojo.class ); Root<Human> root = criteria.from( Human.class );
criteria.select( cb.construct( HumanPojo.class, root.get(Human_.id), root.get(Human_.name), cb.function( "convert", String.class, root.get(Human_.born), cb.literal(110)) ) );
em.createQuery( criteria ).getResultList(); {code} |
|