I just started to use QueryDSL and ran into a problem. Is it possible to do the orderBy using the column name? I found this for orderBy dynamic path generation:
Generic querydsl orderBy dynamic path generation with left joins
which is great, but in my case the GUI already sends column names for ordering. For example, "USER_ID" is the column name, and the property is "userid"
@Entity
@Table(name="USER")
public class User implements java.io.Serializable {
private String userid;
@Id
@Column(name="USER_ID", unique=true, nullable=false, length=18)
public String getUserid() {
return this.userid;
}
}
Extracting property name from column name in hibernate is the only solution I can think of.
I'd appreciate any suggestions.
You can use PathBuilder
for dynamic path construction
PathBuilder<User> pbu = new PathBuilder<>(User.class, "user");
query.orderBy(pbu.getString(orderProperty).asc());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With