你如何选择使用Hibernate的列? [英] How do you select a column using Hibernate?
问题描述
我想选择一个单独的列而不是整个对象,使用Hibernate。到目前为止,我有这样的:
List< String> firstname = null;
firstname = getSession()。createCriteria(People.class).list();
我的问题是,上面的代码将整个People表作为对象返回,而不仅仅是firstname 。我不知道如何指定只返回firstname而不是整个对象。
您可以设置投影例如:
.setProjection(Projections.property(firstname))
有了这个,你只能得到名字作为回报。
我找到了另一个链接与相同的场景堆栈。希望这也能帮助如何使用hibernate标准只返回对象的一个元素而不是整个对象?
I would like to select a single column instead of a whole object, using Hibernate. So far I have this:
List<String> firstname = null; firstname = getSession().createCriteria(People.class).list();
My problem is that the above code returns the whole People table as an object instead of just "firstname". I'm not sure how to specify to only return "firstname" instead of the whole object.
解决方案You can set the Projection for this like:
.setProjection(Projections.property("firstname"))
With this you can only get the firstname in return.
I have found another link on stack with the same scenario. Hope this will also help How to use hibernate criteria to return only one element of an object instead the entire object?
这篇关于你如何选择使用Hibernate的列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!