I had a problem when using JPA with Querydsl and Hibernate to manage the data warehouse. The sample model is as follows:
@Entity
public class User {
....
@ManyToOne
@JoinColumn(name = "CATEGORY_ID")
private Category category;
}
@Entity
public class Category {
..
private String acronym;
@OneToMany(mappedBy = "category")
List<User> userList;
}
In my Spring MVC webapp, I have a search form with user parameters and orderBy. Choosing orderBy can be either a User property or a Category property. OrderBy parameters are saved as Map (fe {"login": "adm", {"firstName": "John"}. The search function accepts the search parameters (as a string) and the map above indicating the order. For ordering:
Map<String, String> orderByMap = new HashMap<String, String>();
orderByMap.put("firstName", "asc");
orderByMap.put("unit.acronym", "desc");
PathBuilder<User> pbu = new PathBuilder<User>(User.class, "user");
....
for (Map.Entry<String, String> order : orderByMap.entrySet())
{
query.orderBy(pbu.getString(order.getKey()).asc());
}
, Category, { "category.acronym", "desc" }. , querydsl - Category , .
, , , . , (, "user.category.subcategory.propetry" ), , .
.