你如何选择使用Hibernate的列? [英] How do you select a column using Hibernate?

查看:94
本文介绍了你如何选择使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆