I\'m using JPA to load and persist entities in my Java EE-based web application. Hibernate is used as an implementation of JPA, but I don\'t use Hibernate-specific features and
What you want is a NamedQuery. On your Order entity you put:
@NamedQueries({ @NamedQuery( name = "getOrderByCustomerId", query = "SELECT o FROM Order o WHERE o.customerId = :customerId") })
Then in your DAO use em.createNamedQuery("getOrderByCustomerId") instead of recreating the query.