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

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

Could not execute JDBC batch update错误有可能是中文问题引起的,如果使用的JBoos4.2GA,别忘了解决中文问题:
1. 设置JBoss的连接编码:URIEcoding="utf-8"
2. 使用filter解决struts中文问题,网上很多这方面的资料

转自:[url]http://blog.csdn.net/derpvailzhangfan/article/details/2332795[/url]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值