我的映射如下所示。
当我更新一个分离的类别项目(不包含任何来自dto转换器的Hibernate类)时,我注意到Hibernate将首先删除所有雇主工资实例(收集链接),然后插入所有雇主工资条目一个接一个:( ...
我知道它必须删除然后插入所有条目,因为它完全分离。
但是,我不明白,为什么Hibernate不通过批量插入插入所有条目? 那就是:在一个SQL语句中插入所有雇主工资条目?
如何告诉Hibernate使用批量插入? (如果可能的话)。 我尝试使用以下值但没有看到任何差异:
hibernate.jdbc.batch_size=30
我的地图摘录:
<class name="com.sample.CategoriesDefault" table="dec_cats" >
<id name="id" column="id" type="string" length="40" access="property">
<generator class="assigned" />
</id>
<component name="incomeInfoMember" class="com.sample.IncomeInfoDefault">
<property name="hasWage" type="boolean" column="inMemWage"/>
...
<component name="wage" class="com.sample.impl.WageDefault">
<property name="hasEmployerWage" type="boolean" column="inMemEmpWage"/>
...
<set name="employerWages" cascade="all-delete-orphan" lazy="false">
<key column="idCats" not-null="true" />
<one-to-many entity-name="mIWaEmp"/>
</set>
</component>
</component>
</class>
答案 0 :(得分:0)
批量插入 - 是快速插入的特定本机方式,通常用于MS SQL的bcp.exe等本机外部工具。 您正在谈论批量插入,尝试使用此示例中的代码:
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
for ( int i=0; i<100000; i++ ) {
Customer customer = new Customer(.....);
session.save(customer);
if ( i % 20 == 0 ) { //20, same as the JDBC batch size
//flush a batch of inserts and release memory:
session.flush();
session.clear();
}
}
tx.commit();
session.close();