本文介绍了org.hibernate.exception.SQLGrammarException:无法获取增量生成器的初始值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用hibernate来编写简单的jsp注册表格,我正在遵循Exception

Hi i am trying to make simple jsp registration form using hibernate where i am getting following Exception

type Exception report

messageInternal Server Error

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

exception

org.apache.jasper.JasperException: org.hibernate.exception.SQLGrammarException: could not fetch initial value for increment generator

root cause

org.hibernate.exception.SQLGrammarException: could not fetch initial value for increment generator

root cause

com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'index) from user_registration' at line 1

这是我的

Userregistration.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">
<!-- Generated Nov 9, 2011 6:53:58 PM by Hibernate Tools 3.2.1.GA -->

          <hibernate-mapping>
          <class name="com.hibernateClass.UserRegistration" table="user_registration">
          <id name="index">
          <generator class="increment"></generator>
          </id>
          <property name="userName"></property>
          <property name="password"></property>
          <property name="email"></property>
          </class>
          </hibernate-mapping>

hibernate.cfg.xml

<?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="hbm2ddl.auto">update</property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/employee</property>
        <property name="connection.username">root</property>
        <property name="connection.password"></property>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="show_sql">true</property>
      <mapping resource="com/hibernateClass/UserRegistration.hbm.xml"/>
    </session-factory>

</hibernate-configuration>

UserRegistration.java

public class UserRegistration  implements java.io.Serializable {


      int index;
      String userName;
      String password;
 String email;
    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }
 }

我如何处理此异常得到我想要的输出

How can i handle this Exceptionand get my desired output

预先感谢

推荐答案

也许'index'是关键字.在sql编程中要小心,有些单词看起来像关键字,应该避免使用它们

maybe 'index' is a keyword .be careful in sql programming , some words look likes keywords ,you should avoid them

这篇关于org.hibernate.exception.SQLGrammarException:无法获取增量生成器的初始值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 03:16