Skip to main content

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: 3
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();
Next Topic:JPA ManyToMany JoinTable - integrity constraint violation: NOT NULL check constraint;
Goto Forum:

Current Time: Mon Mar 30 14:39:34 GMT 2020

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

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

Back to the top