How to use PreparedStatement efficiently?
I like to use the DAO pattern and have a class which do all my SQL request for a particular table and JPA entity. I have for example something like: public class MyDao { @PersistenceContext(name = "mycontext") private EntityManager entityManager; public List<MyEntity> find(String code) { return getEntityManager() .createQuery("FROM MyEntity e WHERE e.code = :code") .setParameter("code", code) .getResultList(); } } But I also know we can use named query directly on the entity class with a static method (I don't like this way): @Entity @Table @NamedQueries({ @NamedQuery(name = "find", query =