1
I have the following packages and classes.
When I’m going to do this JPA consultation, I need to go through the whole full Qualified name of the Class (as in the example) because JPA cannot find it if I pass only its name, no matter the class, it works.
Is there any way to solve this problem? Because I have to migrate some packages here in the project and will break some 20 queries and would have to go in each class and change manually.
br.com.projeto.dao.VendaDAO
br.com.projeto.model.Venda
br.com.projeto.model.VendaTotal
class VendaDao{
public List<VendaTotal> getTotaisDeVentas(){
String jpql =
"select new br.com.projeto.model.VendaTotal(sum v.valor) " +
"from Venda v " +
"group by v.data";
return entityManager.createQuery(jpql, VentaTotal.class).getResultList();
}
}
class Venda{
private Double valor;
private Date data;
// getters e setters
}
class VendaTotal{
private Double valor;
public VentaTotal(Double valor){
this.valor = valor;
}
// getters e setters
}
Are you sure you need to pass the full Qualified name? Ever tried without? Pq in the call of the method you speak which class:
createQuery(jpql, VentaTotal.class)
– igventurelli
@Igorventurelli yes.
– Henrique Santiago