以下是我如何从数据库获取用户 bean。
session.createCriteria(User.class).list();
这将返回数据库中的所有用户记录。有趣的是,我不想从数据库获取密码字段。只是想在检索时排除该字段。
我有的选择
1)使用其他领域的投影。这需要更多代码添加到投影列表中。所以放弃了这个想法。
2)使用Sql,我需要编写一个手动查询,这破坏了Hibernate的主题。
是否有可能排除 Bean 的列值?
你可以试试:
Example example = Example.create(cat)
.excludeZeroes() //exclude zero valued properties
.excludeProperty("color") //exclude the property named "color"
.ignoreCase() //perform case insensitive string comparisons
.enableLike(); //use like for string comparisons
List results = session.createCriteria(Cat.class)
.add(example)
.list();
参考 :-
- http://docs.jboss.org/hibernate/orm/3.6/reference/en-US/html/querycriteria.html#querycriteria-examples
- http://docs.jboss.org/hibernate/orm/3.6/javadocs/org/hibernate/criterion/Example.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)