开发者社区 问答 正文

请教hibernate 查找问题?报错

最近在搞一个c-jdbc的多数据库连接,在测试查找数据是发生下面的情况。
org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: could not execute query; uncategorized SQLException for SQL [select test0_.id as id0_, test0_.name as name0_, test0_.password as password0_ from test test0_]; SQL state [null]; error code [0]; Column 'id0_' not found.; nested exception is java.sql.SQLException: Column 'id0_' not found.


但是后台生成sql语句在数据库能用,但是页面报错。
Hibernate: select test0_.id as id0_, test0_.name as name0_, test0_.password as password0_ from test test0_

展开
收起
爱吃鱼的程序员 2020-06-22 20:38:36 434 分享
分享
版权
举报
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    是不是重点在这里 Column'id0_'notfound看看实体类定义,id属性的注解是不是写的有问题。hql的列名和实体类里面的属性是不是一样的,,,,八成是.hbm配错了。

    表的配置文件

    <hibernate-mapping>
      <classname="com.bean.Test"table="test">
        <idname="id"type="java.lang.Integer">
          <columnname="id"/>
          <generatorclass="increment"/>
        </id>
        <propertyname="name"type="java.lang.String">
          <columnname="name"/>
        </property>
        <propertyname="password"type="java.lang.String">
          <columnname="password"/>
        </property>
      </class>
    </hibernate-mapping>

    <spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:normal;background-color:#FFFFFF;">generator序列模式不知道为什么不能用数据库自增长,所有先用着<spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:normal;background-color:#FFFFFF;">increment增长的方式是按照你的数据库的方式来的,建议写native好一点。应该是ID的问题吧,在研究研究。改一下generator的方式。

    2020-06-22 20:38:53 举报
    赞同 评论

    评论

    全部评论 (0)

    登录后可评论
问答分类:
问答地址:
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等