Hi to all, i have a little issue with Hibernate Criteria. I have 2 entities, one is the super entity of another, as you can see:
Code:
public class ComTiendas implements java.io.Serializable {
private long idtda;
private ComPaises comPaises;
private String nombre;
private String estado;
private String codigoNomina;
private String codigoInv;
private String codigoEmpresa;
//Stuff like constructor, getters and setters .....
}
public class ComPaises implements java.io.Serializable {
private long idpai;
private String nombre;
private String codigoNomina;
private Set comTiendases = new HashSet(0);
//Stuff like constructor, getters and setters .....
}
ComPaises is father of ComTiendas. So, i want to build a query using Hibernate Criteria in the next way:
Code:
Criteria crit = hSession.createCriteria(ComTiendas.class, "tda").createAlias("tda.comVentaDiariaDptos", "vta").
setProjection(Projections.projectionList().
add(Projections.sum("vta.montoVenta")).
add(Projections.groupProperty("idtda")).
add(Projections.groupProperty("nombre")).
add(Projections.groupProperty("codigoNomina")).
add(Projections.groupProperty("codigoInv")).
add(Projections.groupProperty("estado"))
);
I, grouping by the fields of ComTiendas and getting a sum of montoVenta, a field from son entity of ComTiendas. This works well. But the problem is when i want to add to the query a field from father entity, ComPaises, i get an error. I tried in three ways:
1) Adding as an alias to criteria, like this:
Code:
Criteria crit = hSession.createCriteria(ComTiendas.class, "tda").createAlias("tda.comVentaDiariaDptos", "vta").
setProjection(Projections.projectionList().
add(Projections.sum("vta.montoVenta")).
add(Projections.groupProperty("idtda")).
add(Projections.groupProperty("nombre")).
add(Projections.groupProperty("codigoNomina")).
add(Projections.groupProperty("codigoInv")).
add(Projections.groupProperty("estado"))
).createAlias("comPaises.nombre", "nomPais");
And i get this error:
Code:
org.hibernate.QueryException: not an association: nombre
2) Adding as a group property to Projection List:
Code:
Criteria crit = hSession.createCriteria(ComTiendas.class, "tda").createAlias("tda.comVentaDiariaDptos", "vta").
setProjection(Projections.projectionList().
add(Projections.sum("vta.montoVenta")).
add(Projections.groupProperty("idtda")).
add(Projections.groupProperty("nombre")).
add(Projections.groupProperty("codigoNomina")).
add(Projections.groupProperty("codigoInv")).
add(Projections.groupProperty("estado")).
add(Projections.groupProperty("comPaises.nombre"))
);
And i get this error:
Code:
org.hibernate.QueryException: could not resolve property: comPaises.nombre of: com.datasoft.zara.comis.orm.ComTiendas
2) Adding as a property to Projection List:
Code:
Criteria crit = hSession.createCriteria(ComTiendas.class, "tda").createAlias("tda.comVentaDiariaDptos", "vta").
setProjection(Projections.projectionList().
add(Projections.sum("vta.montoVenta")).
add(Projections.groupProperty("idtda")).
add(Projections.groupProperty("nombre")).
add(Projections.groupProperty("codigoNomina")).
add(Projections.groupProperty("codigoInv")).
add(Projections.groupProperty("estado")).
add(Projections.property("comPaises.nombre"))
);
And i get this error:
Code:
org.hibernate.QueryException: could not resolve property: comPaises.nombre of: com.datasoft.zara.comis.orm.ComTiendas
So i don't know the way to include in my query a field of father entity, or isn't possible to do that?
Regards.