---
title: "Hibernate保存对象奇怪问题疑是bug"
author: "DavyLee"
date: "2007-07-13T16:14:49Z"
tags: []
slug: "hibernate-bug"
draft: false
lastmod: "2007-07-13T16:14:49Z"
id: 100779
url: "https://davylee.iteye.com/blog/100779"
---

最近用webwork和hibernate做开发，遇到一个超奇怪的问题，我甚至怀疑是hibernate的一个bug!做了一个用户注册功能，用TableMember对象保存用户的信息，由于要有密码提示问题和答案及找回密码的功能，TableMember和TUserQuestion为多对一的关系。在sql server2000数据库下一切正常；拿到linux的pgsql下发生了问题。问题发生在我用hibernate的saveOrUpdate()方法保存TableMember对象时，发生的错误如下：  
\[code]  
2007-07-13 09:19:43,471 WARN \[org.hibernate.util.JDBCExceptionReporter] - &lt;SQL Error: 0, SQLState: null&gt;

2007-07-13 09:19:43,471 ERROR \[org.hibernate.util.JDBCExceptionReporter] - &lt;Batch entry 0 insert into com\_crazyasp\_rights\_Member (userid, questionId, answer, username, uib\_sex, uib\_nickname, uib\_realname, uib\_birthday, uib\_homeland, uib\_height, uib\_weigth, uib\_tel, uib\_mobile, uib\_qq, uib\_msn, uib\_image, uib\_email, uib\_identity, uib\_postalCode, uib\_address, motto, id) values ( was aborted. Call getNextException() to see the cause.&gt;

2007-07-13 09:19:43,471 WARN \[org.hibernate.util.JDBCExceptionReporter] - &lt;SQL Error: 0, SQLState: 42703&gt;

2007-07-13 09:19:43,472 ERROR \[org.hibernate.util.JDBCExceptionReporter] - &lt;错误: 关系 "com\_crazyasp\_rights\_member" 的 "questionid" 字段不存在

&gt;&lt;o:p&gt; &lt;/o:p&gt;

2007-07-13 09:19:43,474 ERROR \[org.hibernate.event.def.AbstractFlushingEventListener] - &lt;Could not synchronize database state with session&gt;

org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update

       at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:59)

       at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)

       at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:181)

       at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)

       at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)

       at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)

       at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)

       at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)

       at org.springframework.orm.hibernate3.HibernateTemplate$29.doInHibernate(HibernateTemplate.java:815)

       at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:366)

       at org.springframework.orm.hibernate3.HibernateTemplate.flush(HibernateTemplate.java:813)

       at com.crazyasp.common.TableOption.save(TableOption.java:175)  
       补充一下:TableOption.java的175行就是hibernate的saveOrUpdate()方法!  
\[/code]

最直接的错误信息为：&lt;错误: 关系 "com\_crazyasp\_rights\_member" 的 "questionid" 字段不存在,而事实上，数据表com\_crazyasp\_rights\_member中有一个字段是questionId,注意I是大写的；当然映射文件中写的也是column=”questionId”,问题是为什么会出来这样的错误，questionid是哪里来的！  
     我没有办法，把数据库里的questionId字段强行改成了questionid字段，而映射文件里仍然写的是questionId,但这个问题就消失了！真搞不明白，为什么hibernate映射文件里写questionId到了pg数据库里就变成了questionid,等大家一起探讨吧！