Hi to all! i want to know if its posible to join Projections i mean this:
Code:
@Entity
public class Root{
@OneToOne
private ChildOne childa;
@OneToOne
private ChildTwo childb;
}
Code:
@Entity
public class ChildOne{
String name;
// another things...
}
Code:
@Entity
public class ChildTwo{
String name;
// another things
}
So i have a list of Objects that contains Root asosiations
i want to order the name by Desc or Asc
The problem is that sometimes ChildOne is null and other time ChildTwo is null
so i cant order them in the right way
this my criteria:
Code:
session.createCriteria(Movimiento.class)
.createAlias("destino","destino")
.createAlias("destino.almacen","a",CriteriaSpecification.LEFT_JOIN)
.createAlias("destino.sucursal","s",CriteriaSpecification.LEFT_JOIN)
.setProjection(Projections.projectionList()
.add(Projections.property("a.nombre").as("almacen_nombre"))
.add(Projections.property("s.nombre").as("sucursal_nombre"))
)
.addOrder(Order.desc("almacen_nombre"))
.addOrder(Order.desc("sucursal_nombre"))
the result is something like due the left JOIN:
A almacen
B almacen
C almacen
A sucursal
B sucursal
C sucursal
The problem is that projections first order "destino.almacen" and then "destino.sucursal"
i there a way to join the results of that projections so i can order that unique result?
so i can get something like this:
A almacen
A sucursal
B almacen
B sucursal
C almacen
C sucursal
Any kind of help would be apreciated.
PD: i made in SQL whit a UNION but Hibernet doesn't suport it (or iam wrong?)