mardi 22 janvier 2019

How can I Order By a nested property in my entity through querydsl web support? Is it possible?

I'm trying to support sorting through querydsl web support for all properties in my entity and this works fine for the first level properties. On the other hand, when trying to sort through @ManyToOne annotated properties though, the param sent throught the URL is ignored.

Is this behaviour even achievable through querydsl? If so: Is there any setup/config required for querydsl to support this?

Let's say User entity is:

 @Data
 @Entity
 @Audited
 @EntityListeners(AuditingEntityListener.class)
 @AuditOverride(forClass = Auditable.class)
 public class User extends Auditable implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column
    private String name;

    @ManyToOne
    @JoinColumn(name = "type_id", nullable =  true, foreignKey = 
    @ForeignKey(name = "type_id"))
    private Type type;    

}

Then Type is:

@Data
@Entity
@Audited
@EntityListeners(AuditingEntityListener.class)
@AuditOverride(forClass = Auditable.class)
public class User extends Auditable implements Serializable {

   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   private Long id;

   @Column
   private String typeName;

}

I'd expect that calling /users?sort=type.typeName,desc would respond with a sorted user list sorted by typeName in descending order but the param just gets ignored.

sort might not be the param expected by querydsl, but I haven't been able to found a list of allowed predicates for websupport




Aucun commentaire:

Enregistrer un commentaire