Hibernate sort by internal bean properties?

In my domain model, I have the following classes. "UserProfile" has one "SecurityPrincipal"

class SecurityPrincipal{
 private String loginId;
 private String password;
 private Date registeredData;
 private int status;
}



class UserProfile {

private String name;
private String company;
private SecurityPrincipa principal

}

I want to get the sorted results of UserProfile objects and works fine for simple properties. how

DetachedCriteria criteria=DetachedCriteria.forClass(UserProfile.class);     

criteria.addOrder(Order.asc("name");

But when I try to access the properties of the internal bean (SecurityPrincipal instance), for example

criteria.addOrder(Order.asc("principal.status");

Sleep mode throws an error:

: org.hibernate.QueryException: : securityPrincipal.status of: com.bigg.ibmd.usermanagement.model.UserProfile    org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:44)    org.hibernate.persister.entity.AbstractPropertyMapping.toColumns(AbstractPropertyMapping.java:59)    org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:31)

?

+3
2

:

DetachedCriteria criteria=DetachedCriteria.forClass(UserProfile.class);         
criteria.createAlias("principal", "p");
criteria.addOrder(Order.asc("p.name"));

, , , , .

+4

@OrderBy. :

@OrderBy ( "id, name, whatever" ) ...

, JPA api 2.0 OUTER JOIN . , " ", " ", :

@OrderBy ( ", " ) userVitalStatsCollection;

, .

0

Source: https://habr.com/ru/post/1726029/


All Articles