Create a JPQL and set the entity at runtime

0

Good evening.

I would like to know if there is a way to do a JPQL query and set the entity at runtime, without having to concatenate or interpolate String.

Example using interpolation:

public long getRecords(String entity){
    String q = String.format("COUNT(e) FROM %s e", entity);
    Query query = em.createQuery(q);
    return (long) query.getSingleResult();
}
    
asked by anonymous 05.02.2017 / 04:10

0 answers