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:
FROM PlanillaTraslado pt
WHERE ... 
ORDER BY pt.chofer.apellido, pt.chofer.nombre

This is the entity
public class PlanillaTraslado implements Serializable {

    private static final long serialVersionUID = 1L;
    @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)
    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: Wed Feb 21 17:34:33 GMT 2018

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

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