三大架構整合 提示 不能進行查詢錯誤

來源:互聯網
上載者:User

這是拋出來的提示資訊:

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 queryorg.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>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.