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

来源:互联网 发布:剑灵灵女萌妹子数据 编辑:程序博客网 时间:2024/05/21 10:13

         今天用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

  

原创粉丝点击