三大框架整合 提示 不能进行查询错误

28 篇文章 3 订阅
13 篇文章 0 订阅

这是抛出来的提示信息:

HTTP Status 500 - could not execute query; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query


type Exception report

message could not execute query; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
	org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:613)
	org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)

提示是无法进行查询,我们可以把他生成的sql 复制在sql editer中去运行下,你就会发现错误了

很有可能是因为表名 或者字段名 是sql的关键字引起的。

在bean的hbm.xml 文件中给字段 或者 表名加上回避符就可以了。[表名]

附上一段我报错的配置文件,修复正确的:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- 
    Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
    <class name="com.shop.bean.Order" table="[Order]" schema="dbo" catalog="Shop" dynamic-insert="true" dynamic-update="true">
        <id name="id" type="java.lang.Integer">
            <column name="Id" />
            <generator class="native" />
        </id>
        <many-to-one name="product" class="com.shop.bean.Product" fetch="select">
            <column name="ProductId" not-null="true" />
        </many-to-one>
        <many-to-one name="user" class="com.shop.bean.User" fetch="select">
            <column name="UserId" not-null="true" />
        </many-to-one>
        <many-to-one name="convey" class="com.shop.bean.Convey" fetch="select">
            <column name="ConveyId" not-null="true" />
        </many-to-one>
        <property name="price" type="java.lang.Double">
            <column name="[Price]" scale="4" not-null="true" />
        </property>
        <property name="count" type="java.lang.Integer">
            <column name="[Count]" not-null="true" />
        </property>
        <property name="money" type="java.lang.Double">
            <column name="[Money]" scale="4" not-null="true" />
        </property>
        <property name="shipments" type="java.lang.Boolean">
            <column name="Shipments" />
        </property>
        <property name="address" type="java.lang.String">
            <column name="[Address]" not-null="true" />
        </property>
        <property name="receive" type="java.lang.Boolean">
            <column name="Receive" />
        </property>
        <property name="addTime" type="java.sql.Timestamp">
            <column name="AddTime" length="23" />
        </property>
    </class>
</hibernate-mapping>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值