休眠条件搜索多个实体
我有三个实体:日志、员工和代理机构
日志,其中与员工
有多对一关联。 员工与代理机构有多对一关联
DetachedCriteria criteria = DetachedCriteria.forClass(Log.class);
if (StringUtils.isNotBlank(c.getName())) {
criteria.createAlias("employee", "e").add(Restrictions.ilike("e.name", "%" + c.getName() + "%"));
}
if (StringUtils.isNotBlank(c.getAgency())) {
criteria.createAlias("employee", "e").createAlias("agency", "a").add(Restrictions.ilike("e.a.name", "%" + c.getAgency() + "%"));
}
。 以上适用于员工名称,但不适用于代理机构名称。
我收到以下错误:
Exception: org.hibernate.QueryException: could not resolve property: agency of: com.example.Log
我找到的所有示例仅向下一级。有人可以向我指出一个资源,告诉我如何向下导航吗?
I have three entities: Log, Employee, and Agency
Log with a many to one association to Employee
Employee with a many to one association to Agency
DetachedCriteria criteria = DetachedCriteria.forClass(Log.class);
if (StringUtils.isNotBlank(c.getName())) {
criteria.createAlias("employee", "e").add(Restrictions.ilike("e.name", "%" + c.getName() + "%"));
}
if (StringUtils.isNotBlank(c.getAgency())) {
criteria.createAlias("employee", "e").createAlias("agency", "a").add(Restrictions.ilike("e.a.name", "%" + c.getAgency() + "%"));
}
The above works for Employee name, but it doesn't work for Agency name.
I get the below error:
Exception: org.hibernate.QueryException: could not resolve property: agency of: com.example.Log
All the examples I find only go one level down. Can someone point me to a resource that tells me how to navigate lower?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试下面的代码
Try the following code
第二个应该像这样工作:
The second one should work like this: