0
Good night.
I wonder if there is a way to make a JPQL query and define 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();
}
You can give a better example?
String
has not the methodgetSingleResult()
. In addition, I would like to know in what context this method is used and where you get the parameter passed to the method, because this is important to be able to elaborate a response. In particular I wonder if you have how to know which is the objectClass<?>
of its entity.– Victor Stafusa
I added the rest of the code. This method will be called during a user request. It will fill in the fields that will be generated in the database. I have no way of knowing Class<? > why the entity will be generated from a file. properties.
– helciodasilva
@helciodasilva has classes involved, that is, in addition to this Count in the table, there is the class that returns the content of a row or rows of a table?
– novic
Virgil, there isn’t. I just need to check if a table is empty.
– helciodasilva