hibernate的Could not execute JDBC batch update错误原因及处理

         今天用hibernate做系统的时候,出现了Could not execute JDBC batch update错误,现在已经解决。

先说说我的代码:

         这是角色表对应的配置文件,当我在角色管理列表的jsp页面里删除选中的角色信息,就报了上面的错误。

<?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="com.cms.po.Trole" table="trole">
        
<id name="roleId" type="integer">
            
<column name="roleId" />
            
<generator class="native" />
        
</id>
        
<property name="roleName" type="string">
            
<column name="roleName" length="50" />
        
</property>
        
<property name="isDel" type="string">
            
<column name="isDel" length="2" />
        
</property>
        
<property name="roleDescribe" type="string">
            
<column name="roleDescribe" length="500" />
        
</property>
        
<property name="createTime" type="string">
            
<column name="createTime" length="32" />
        
</property>
        
        
<!-- 创建的用户id 一对一 --> 
        
<many-to-one
              
name="tsysuser"
              column
="userId"
              unique
="true"
              class
="com.cms.po.Tsysuser" lazy="false"/> 
        
    
</class>
</hibernate-mapping>

        每创建角色,都对应着创建人的id,但是我为了测试省事,直接把数据插进表里,并且没有在表里插入创建人的userId,再看看代码:

      

/**
     * 批量删除角色
     
*/

    
public boolean deleteRoles(String roleids) throws Exception {        
        String[] roleidArray 
= roleids.split(",");
        
for(int i=0; i<roleidArray.length; i++){
            Trole trole 
= (Trole)this.getHibernateTemplate().get(Trole.class,new Integer(roleidArray[i]));
            trole.setIsDel(
"1");
            
this.getHibernateTemplate().saveOrUpdate(trole);
        }

        
return true;        
    }

没有什么问题,但是却报了Could not execute JDBC batch update的错,主要是配置文件设置了关联,数据却没有关联造成的,只要数据正确就没有问题。

另外,造成这个原因的还可能是数据库的驱动jar包不支持。

还有就是csdn的dizhang的专栏提到的下面问题引起的:

1.因为Hibernate Tools(或者Eclipse本身的Database Explorer)生成*.hbn.xml工具中包含有catalog="***"(*表示数据库名称)这样的属性,将该属性删除就可以了
2.估计是你的列名里面有关键字的原因吧,命名列的时候不要单独使用date,ID...这种关键字 

Hibernate查询时候的问题。
莫名其妙地报如下的错误,
org.hibernate.exception.GenericJDBCException: could not execute query

  

阅读更多
换一批

Hibernate operation: Could not execute JDBC batch update;

04-10

1:STRUTS+HIBERNATE+SPRING框架 原来项目的数据库是SQL2000,原来所有表是HIBERNATE生成的主键是用UUIX,现在改成ORACLE后随便运行一个保存测试用例的时候,会出现主键为空的异常.rn也就是UUIX在ORACLE不生成,也就不能插入.如果重新在ORACLE的一张表上生成一个表 做保存的话 是没问题的.不可能在把原来的整个项目的表都去生成一遍,请问怎么改?rnrn谢谢..异常如下:rnorg.springframework.jdbc.BadSqlGrammarException: Hibernate operation: Could not execute JDBC batch update; bad SQL grammar [insert into cms_cnparts.dbo.T_LINK (linkName, typeID, linkUrl, picture, linkIntro, createTime, email, tel, isPass, orderID, memberID, linkID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)]; nested exception is java.sql.BatchUpdateException: ORA-00926: missing VALUES keywordrnrnCaused by: java.sql.BatchUpdateException: ORA-00926: missing VALUES keywordrnrn at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:459)rn at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:3907)rn at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)rn at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)rnrnHIBERNATE配置如下:rn rn rn org.hibernate.dialect.OracleDialectrn rn rn jdbc:oracle:thin:@10.241.96.123:1521:ORA9Irn rn elplatrn elplat_168rn rn oracle.jdbc.driver.OracleDriverrn rn rn cms_cnpartsrn rn rn threadrn truernrn/************************************rn随便一张表的映射如下rnrnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrn

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

07-15

Books.hbm.xml 内容:rnrnrnrnrn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rn rnrnrnjava 代码内容:rnpublic class Test rnrn public static void main(String[] args) rnrn try rn SessionFactory sf = new Configuration().configure().buildSessionFactory();rn Session session = sf.openSession();rn Transaction tx = session.beginTransaction();rn Books pd = new Books();rn pd.setBookId(1);rn pd.setBookName("教父");rn pd.setBookAuthor("Godfather");rn pd.setBookPublish("1"); rn pd.setBookIsbn("DVD");rn session.save(pd);rn tx.commit();rn session.close();rn System.out.println("dfsfsdfsdf");rn catch (HibernateException e) rn e.printStackTrace();rn rn rnrnrn报错信息:rnHibernate: insert into books (book_name, bookAuthor, book_publish, book_date, book_isbn, book_page, book_price, book_content, bookId) values (?, ?, ?, ?, ?, ?, ?, ?, ?)rnorg.hibernate.exception.SQLGrammarException: Could not execute JDBC batch updatern at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)rn at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)rn at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:181)rn at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)rn at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)rn at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)rn at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)rn at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)rn at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)rn at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)rn at root.Test.main(Test.java:25)rnCaused by: java.sql.BatchUpdateException: Unknown column 'bookAuthor' in 'field list'rn at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1257)rn at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:943)rn at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)rn at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:174)rn ... 8 morernrn搞了 2天了,还是不知道什么原因,请 大侠 支援下!

没有更多推荐了,返回首页