我在Oracle数据库有一个表CompanyList:春/休眠 - 过滤器由当前用户ID
CMP_ID INTEGER -- ID of company
CMP_NAME VARCHAR2 -- name of company
USR_ID INTEGER -- Foreign key to the USERS table
我有我的春天3 MVC应用程序都使用注释,我的POJO和配置,我的DAO对象( CompanyDao)使用hibernate检索公司列表。
CompanyDao:
@Transactional
public Set<Company> findAllCompanys() throws DataAccessException {
return findAllCompanies(-1, -1);
}
@SuppressWarnings("unchecked")
@Transactional
public Set<Company> findAllCompanies(int startResult, int maxRows) throws DataAccessException {
Query query = createNamedQuery("findAllCompanies", startResult, maxRows);
return new LinkedHashSet<Company>(query.getResultList());
}
而我的公司域名:
@Entity
@NamedQueries({
@NamedQuery(name = "findAllCompanies", query = "select myCompany from Company myCompany")})
...
public class Company implements Serializable {
...
然后我设置春天的安全性,所以我所有的页面需要鉴定。
使用当前登录的用户会话的用户ID过滤由CompanyDao返回的行的最佳方式是什么?