检索Hibernate查询结果作为结果集而不是列表 [英] Retrieving Hibernate query result as result set instead of list
问题描述
我是hibernate的新手。我不得不说它确实简化了SQL查询的所有内容。然而,操纵返回的结果对我来说现在头疼。
结果以列表形式返回。大多数情况下,我真的希望将结果放在结果集中,以便我可以使用结果集更容易地操作它,您可以按列名或索引指定值。在List中,我几乎拥有自己的noobity。
在某些情况下,我可以将列表检索到JSF数据表中,然后直接调用成员。我不能总是这样做。不要问我为什么。 @。@纺纱头。
有没有一种方法可以获取结果集而不是hibernate的列表?
好吧,我设法让它工作!我很开心!
对于那些试图找到如何操作由Hibernate查询返回的列表的人,基本上我所做的是......
//先前的代码
list =(List< MappedClass>)query.list();
从那里列表将包含映射类,您可以通过迭代器访问它,随后使用getter来检索价值。
示例
//先前的代码
for(int i = 0; i< list.size ); i ++){
字符串名称;
字符串ID;
name = list.get(i).getName();
id = list.get(i).getId();
//在这里添加数据操作
}
这有助于。
Heya, I m new to hibernate. I have to say it really simplifies everything for the SQL query. However, manipulating the returned result is a headache for me at the moment.
The result is returned as list. Most of the time I really want the result to be in result set so that I can manipulate it easier as using result set, you can specifies value by column name or index. In List, I am pretty much owned by own noobity.
In some ocassion, I can retrieve the list into a JSF data table and then just call the member directly. I cannot always do this. Don't ask me why. @.@ spinning head.
Is there a way to get resultset instead of list for hibernate?
Ok, somehow I managed to make it work! Me so happy! For those who trying to find on how to manipulate the list returned by Hibernate query, basically what I did was..
//previous code
list = (List<MappedClass>)query.list();
From there the list shall contain mapped class and you can access it by iterator and subsequently uses getter to retrieve the value. Example
//previous code
for (int i =0; i<list.size(); i ++) {
String name;
String id;
name = list.get(i).getName();
id = list.get(i).getId();
//add your data manipulation here
}
Hope this helps.
这篇关于检索Hibernate查询结果作为结果集而不是列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!