在休眠mysql中批量插入/更新 [英] batch insert/update in hibernate mysql

查看:123
本文介绍了在休眠mysql中批量插入/更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用容器管理的交易.应用服务器JBOSS AS7.我已经在休眠配置文件中启用了以下属性

We are using container managed transaction . Application server JBOSS AS7 . I have enabled the below properties in hibernate configuration file

<property name="hibernate.connection.url">jdbc:mysql://localhost/test?rewriteBatchedStatements=true</property> 
<property name="hibernate.jdbc.batch_size" value="20"/> 
<property name="hibernate.order_inserts" value="true"/> 
<property name="hibernate.order_updates" value="true"/> 
<property name="hibernate.jdbc.batch_versioned_data" value="true"/>

并启用如下所示的日志记录属性

And enabled the logging property as below

<logger category="org.hibernate.SQL">
    <level name="TRACE"/>
</logger>

我正在向数据库插入10条记录. 在hibernate.log中,我可以看到10条如下的插入语句

I am inserting 10 records to the database. In the hibernate.log , i could see 10 insert statements as below

org.hibernate.sql insert into test (name,value,date) values (?,?,?) org.hibernate.sql insert into test (name,value,date) values (?,?,?)  

批量插入无效

推荐答案

很可能您实际上正在使用批处理.只是Hibernate为每个实体实例打印单独的sql.

Very probably you are actually using batching; it is just that Hibernate prints separate sql for each entity instance.

要对此进行检查,请为org.hibernate包启用DEBUG日志级别(如果要查看绑定变量,请为org.hibernate.type启用TRACE级别),然后检查日志中是否出现以下短语:

To check this, enable DEBUG log level for org.hibernate package (and TRACE level for org.hibernate.type if you want to see bound variables), then check if the following phrases appear in the log:

  • 重用批处理语句

  • Reusing batch statement

执行批量大小

如果为执行的批次大小打印了大于1的数字,则说明您正在使用批次.

If a number larger than 1 is printed for executed batch size, then you are using batching.

特定于MySQL,要确保MySQL驱动程序重写插入语句,请按照

Specific to MySQL, to make sure that MySQL driver rewrites insert statements, enable profileSQL parameter in connection url as described here.

注意::JDBC批处理是 (如果已使用IDENTITY id生成器).

NOTE: JDBC batching is disabled if IDENTITY id generator is used.

这篇关于在休眠mysql中批量插入/更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆