浏览 2380 次
锁定老帖子 主题:请教关于Hibernate的一个问题!
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-05-11
最后修改:2008-11-21
异常1: 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) values ('123', 4)' at line 1 异常2: org.hibernate.exception.SQLGrammarException: could not insert: [qau.cookbook.hibernate.po.basedata.Foodkindctrl] 下面是我的数据库表的映射文件: <hibernate-mapping> <class name="qau.cookbook.hibernate.po.basedata.Foodkindctrl" table="foodkindctrl" catalog="cookbook"> <id name="id" type="integer"> <column name="id" /> <generator class="identity" /> </id> <property name="foodkindctrlname" type="string"> <column name="foodkindctrlname" length="20" /> </property> <property name="index" type="integer"> <column name="index" /> </property> <set name="foodkinddtls" inverse="true"> <key> <column name="foodkindctrlid" /> </key> <one-to-many class="qau.cookbook.hibernate.po.basedata.Foodkinddtl" /> </set> </class> </hibernate-mapping> 下面是pojo类文件: public class Foodkindctrl implements java.io.Serializable { // Fields private Integer id; private String foodkindctrlname; private Integer index; private Set foodkinddtls = new HashSet(0); // Constructors /** default constructor */ public Foodkindctrl() { } /** full constructor */ public Foodkindctrl(String foodkindctrlname, Integer index, Set foodkinddtls) { this.foodkindctrlname = foodkindctrlname; this.index = index; this.foodkinddtls = foodkinddtls; } // Property accessors public Integer getId() { return this.id; } public void setId(Integer id) { this.id = id; } public String getFoodkindctrlname() { return this.foodkindctrlname; } public void setFoodkindctrlname(String foodkindctrlname) { this.foodkindctrlname = foodkindctrlname; } public Integer getIndex() { return this.index; } public void setIndex(Integer index) { this.index = index; } public Set getFoodkinddtls() { return this.foodkinddtls; } public void setFoodkinddtls(Set foodkinddtls) { this.foodkinddtls = foodkinddtls; } } 下面是我写的插入函数: public boolean saveKindCtrl(Foodkindctrl kindCtrl){ Transaction tx=null; try{ Session session = HibernateSessionFactory.getSession(); tx = session.beginTransaction(); session.save(kindCtrl); tx.commit(); log.debug("保存成功"); return true; }catch(Exception e){ e.printStackTrace(); log.debug("保存失败"); return false; }finally{ HibernateSessionFactory.closeSession(); } } 请问各位高手为什么会出现这样的问题,该如何解决呢? 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2008-05-20
index在MySQL里是关键字,属性index对应的列名不要用index
|
|
返回顶楼 | |
发表时间:2008-05-20
谢谢楼上的回答,问题确实出在这个地方,前几天刚刚解决。
|
|
返回顶楼 | |