Hibernate Criteria 查询连接与空值
我有一个名为角色的表。每个角色可能属于一个组织。不属于组织的角色的值为 null。我想查找特定组织的所有角色或该组织在表中为空的位置。
Criteria criteria = this.sessionFactory.getCurrentSession().createCriteria(Role.class)
.add(Restrictions.or(
Restrictions.eq("organization",organization.getId()),
Restrictions.isNull("organization")));
映射文件具有:
<many-to-one class="com.myname.models.Organization" name="organization">
<column name="organization_id" precision="22" scale="0" />
</many-to-one>
当查询运行时,我得到:
IllegalArgumentException occurred calling getter com.myname.models.Organization.id
我发现如果我修改条件以仅查询组织上的空值,一切都会正常,但是一旦我查询一个值,我就会收到错误。
如何修改查询或映射文件以满足我的目标?
I have a table called roles. Each role may belong to an organization. Roles that do not belong to an organization have a value of null. I want to find all the roles for a specific organization or where the organization is null within the table.
Criteria criteria = this.sessionFactory.getCurrentSession().createCriteria(Role.class)
.add(Restrictions.or(
Restrictions.eq("organization",organization.getId()),
Restrictions.isNull("organization")));
The Mapping file has:
<many-to-one class="com.myname.models.Organization" name="organization">
<column name="organization_id" precision="22" scale="0" />
</many-to-one>
When the query runs, I get:
IllegalArgumentException occurred calling getter com.myname.models.Organization.id
I have found that if I modify the criteria to just query for nulls on organization everything works, however once I query for a value, I get the error.
How to I modify the query or mapping file to meet my goals?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定您是否仍在寻找答案,但由于我在寻找同一问题的解决方案期间遇到了此线程,我认为它可能对将来的参考有所帮助。
您需要按如下方式构建您的标准:
Not sure whether you're still looking for the answer, but as I've encountered this thread during my search for a solution of the same problem, I though it might be helpful for future reference.
You'll need to construct your criteria as follows:
这似乎表明您在某个地方使用了“组织”,而该地方应该是“组织”。
This seems to suggest that you are using "Organiation" somewhere whhere presumably this should be "Organization".