SQL和HQL大小写敏感问题

来源:互联网 发布:中国金融数据库 编辑:程序博客网 时间:2024/06/05 16:30

今天在做Hibernate案例的时候,表单中接收的数据总是不对,利用谷歌浏览器F12打断点调试,传入的

参数出现了下面这种错误信息:

"<html><head>    <title>Struts Problem Report</title>    <style>    pre {    margin: 0;        padding: 0;    }        </style></head><body>    <h2>Struts Problem Report</h2>    <p>    Struts has detected an unhandled exception:    </p><div id="exception-info"><table>    <tr>        <td><strong>Messages</strong>:</td>        <td>            <ol>                        <li>student is not mapped</li>                        <li>student is not mapped [from student where id=:id and pwd=:pwd ]</li>            </ol>        </td>    </tr>    <tr>        <td><strong>File</strong>:</td>        <td>org/hibernate/hql/internal/ast/util/SessionFactoryHelper.java</td>    </tr>    <tr>        <td><strong>Line number</strong>:</td>        <td>189</td>    </tr>    </table></div><div id="stacktraces"><hr /><h3>Stacktraces</h3><div class="stacktrace" style="padding-left: 0em">    <strong>org.hibernate.hql.internal.ast.QuerySyntaxException: student is not mapped [from student where id=:id and pwd=:pwd ]"

最后发现我的实体(Entity)是这样命名的,Student.java,而我的HQL语句是这样写的:

                   String hql = "from student where id=:id and pwd=:pwd";

当我把上面的student改写成Student后,程序就好使了。

这里我们可以意识到,SQL和HQL对待大小写是不同的:

SQL语句默认对大小写是不敏感的,即大写和小写是一样的。可以通过设置更改。

  HQL对大小写是敏感的,原因是,HQL是面向对象的查询语句,里面的类名和属性名一定要和实体类的相对应

首字母大写,属性名也要和getAbc()方法的一致,即abc。





1 0