开发者社区> 问答> 正文

请教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 407 0
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
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载