如何在休眠中编写查询来选择列 [英] how to write a query in hibernate to select a column

查看:119
本文介绍了如何在休眠中编写查询来选择列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用hibernate模板从表课程中检索数据,该表有两列,
courseId courseName 。我想使用hibernate模板从 course 选择 courseName



 列表< String> courseNames = hibernateTemplate.find(domainName from course.Course); 

我收到以下异常:

  java.lang.IllegalArgumentException:要遍历的节点不能为null! 


解决方案

您需要使用完整形式的 select query:

 从domain.Course中选择c.courseName c 

另请参阅:

  • 16.6。 select语句


  • I'm using hibernate template to retrieve a data from the table course which has two columns, courseId and courseName. I want to select courseName from course using hibernate template.

    When I use:

    List<String> courseNames=hibernateTemplate.find("courseName from domain.Course");
    

    I get the following exception:

    java.lang.IllegalArgumentException: node to traverse cannot be null!
    

    解决方案

    You need to use a full form of select query:

    select c.courseName from domain.Course c
    

    See also:

    这篇关于如何在休眠中编写查询来选择列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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