首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Exception >

hibernate出现异常org.hibernate.exception.SQLGrammarException:could not execute query

2014-01-26 
环境:myeclipse4.0+eclipse3.1+mysql5.0,在eclipse里新建了一个Web 工程,然后加入了hibernate的jar文件,数

环境:myeclipse4.0+eclipse3.1+mysql5.0,
 
  在eclipse里新建了一个Web 工程,然后加入了hibernate的jar文件,
  数据库只有一个表,
  数据库名sample,表名message,表的字段如下:
  id
  text
  nextMessage
 
  进行了映射,
  下面是映射文件Message.hbm.xml
  <?xml version="1.0"?>
  <!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 - Hibernate Tools
  -->
  <hibernate-mapping>
  <class name="hibernate.mapping.Message" table="message" catalog="sample">
  <id name="id" type="string">
  <column name="id" length="50" />
  <generator class="uuid.hex" />
  </id>
  <property name="text" type="string">
  <column name="text" length="50" />
  </property>
  <property name="nextMessage" type="integer">
  <column name="nextMessage" />
  </property>
  </class>
  </hibernate-mapping>
 
  下面是hibernate配置文件:
  <?xml version='1.0' encoding='UTF-8'?>
  <!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
 
  <!-- Generated by MyEclipse Hibernate Tools.   -->
  <hibernate-configuration>
 
  <session-factory>
  <property name="connection.username">root</property>
  <property name="connection.url">jdbc:mysql://localhost:3306/sample</property>
  <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
  <property name="myeclipse.connection.profile">mysqlconnector</property>
  <property name="connection.password">12</property>
  <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
  <property name="show_sql">true</property>
  <mapping resource="hibernate/mapping/Message.hbm.xml" />
 
  </session-factory>
 
  </hibernate-configuration>
 
  然后建了一个index.jsp进行测试,下面是index.jsp
 
  <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>         

热点排行