专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Java Exception

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

发布时间:2010-06-05 12:35:00 文章来源:www.iduyao.cn 采编人员:星星草

环境: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"%>     

友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: