-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Projections - Help please
PostPosted: Fri Apr 29, 2011 3:39 pm 
Newbie

Joined: Fri Apr 29, 2011 3:21 pm
Posts: 6
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?)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.