Hibernate @Where子句 [英] Hibernate @Where clause
问题描述
@Where(clause =enabled = 1 and deleted = 0 )
@Fetch(FetchMode.SUBSELECT)
public Set< Group> getGroups(){
返回组;
}
但是当我试图在 Group
,它已经存储在数据库中,不适合 @Where
子句,Hibernate忽略了我。
实际上, @Where
不是我的决定,但是我可以找到解决方法来解决这个问题(创建另一个dao方法来执行一些操作)非常难看。
那么,是否有办法克服这个问题?或者我错过了什么?感谢您的帮助。
根据您的类型启用
和删除
字段,您必须以不同的形式编写 @Where
子句。
如果您的字段是数字:
@Where(clause =enabled = 1 and deleted = 0 )
如果您的字段是字符串:
< pre $ @Where(clause =enabled ='1'and deleted ='0')
如果您的字段是布尔型的:
@Where(clause =enabled = true and deleted = false)
检查您的类型(在您的Java类和数据库中) @Where
以正确的方式。
I have User class, which has groups.
@Where(clause = "enabled = 1 and deleted = 0")
@Fetch(FetchMode.SUBSELECT)
public Set<Group> getGroups() {
return groups;
}
But when I'm trying to make some operation on Group
which is already stored in DB and is not suitable for @Where
clause, Hibernate just ignores me.
Actually, @Where
is not my decision, but solution I could find to overcome this (create another dao method to perform some operation) is so ugly.
So, is there way to overcome this? Or did I miss something? Thanks for the help.
Depending on the type of your enabled
and deleted
fields, you must write your @Where
clause in a different form.
If your fields are numerics:
@Where(clause = "enabled = 1 and deleted = 0")
If your fields are Strings:
@Where(clause = "enabled = '1' and deleted = '0'")
If your fields are boolean:
@Where(clause = "enabled = true and deleted = false")
Check your types (in your Java class and in your database too) and use your @Where
in the correct way.
这篇关于Hibernate @Where子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!