我有一个用户实体,它被建模为
@Entity
class User {
@ManyToMany
@JoinTable(name="user_roles",
joinColumns=@JoinColumn(
name="user_id", referencedColumnName="id"),
inverseJoinColumns=@JoinColumn(
name="role_id", referencedColumnName="id")
)
public Set<Role> getRoles() {
return roles;
}
}
我想在分页视图中列出此用户特定角色。对于其他类,我正在使用这样的 HibernateTemplate
public PagedBean<User> findUsers(inal Status status, final PageParameters pageParameters) {
return (PagedBean<User>) hibernateTemplate.execute(new HibernateCallback(){
public Object doInHibernate(Session session) throws HibernateException, SQLException {
Criteria crit = getUserByStatusCriteria(status, session);
crit.addOrder(Order.asc("id"));
Criteria critWithoutOrder = getUserByStatusCriteria(status, session);
PagedResultBean<RssFeedSource> pagedResultBean = new PagedBean<User>(pageParameters);
return populateFromCriteria(crit, critWithoutOrder, pagedBean);
}
private Criteria getUserByStatusCriteria(final Status status, Session session) {
Criteria c = session.createCriteria(User.class);
c.add(Restrictions.eq("status", status));
return c;
}});
}
对于不是实体的“user_roles”,如何实现与上述相同的分页结果?