Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Criteria OrderBy(How to order by attributes of attributes)
Criteria OrderBy [message #1737831] Wed, 13 July 2016 11:01
jose luis romero is currently offline jose luis romeroFriend
Messages: 1
Registered: July 2016
Junior Member
How can I achieve this JPA query (the ORDER BY part) into a Criteria one:
SELECT pt
FROM PlanillaTraslado pt
WHERE ... 
ORDER BY pt.chofer.apellido, pt.chofer.nombre


This is the entity
@Entity
public class PlanillaTraslado implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    @JoinColumn(nullable = false)
    @ManyToOne(optional = false)
    private Chofer chofer;
    /**
     * Debe existir una por cada día de trabajo
     */
    @Column(nullable = false)
    @Temporal(TemporalType.DATE)
    private Date fecha;


This is the basic query where I want to add the OrderBy
 public List<PlanillaTraslado> findBy(Date day) {
        CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
        CriteriaQuery<PlanillaTraslado> cq = cb.createQuery(getEntityClass());
        Root<PlanillaTraslado> from = cq.from(cq.getResultType());
        cq.where(cb.equal(from.get(PlanillaTraslado_.fecha), day));
        return getEntityManager().createQuery(cq).getResultList();
    }
Previous Topic:Access raw unmapped data from Entity
Next Topic:Persist @ElementCollection Map - The list of fields to insert into the table is empty
Goto Forum:
  


Current Time: Tue Dec 12 15:51:13 GMT 2017

Powered by FUDForum. Page generated in 0.01621 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software