[英]Hibernate getting only column1 from a query returning multiple columns
I have a query of this nature 我对此性质有疑问
String query = select column1, group by column2 from table1 ...
//What should I write to just get column1 from the query.
getSession().createQuery(query).list();
How do I get just columne1 list from the query. 如何从查询中获取columne1列表。
With hibernate HQL/JPQL queries you don't get get columns. 使用休眠的HQL / JPQL查询不会获得get列。 You get objects and their properties. 您将获得对象及其属性。 So: 所以:
String query = "SELECT yourEntity.property1 FROM yourEntity .....";
Then the list()
will return a List<Foo>
, where Foo
is the type of property1
然后list()
将返回List<Foo>
,其中Foo
是property1
的类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.