Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Hibernate中大容量插入组件集合?_Hibernate_Hibernate Mapping - Fatal编程技术网

在Hibernate中大容量插入组件集合?

在Hibernate中大容量插入组件集合?,hibernate,hibernate-mapping,Hibernate,Hibernate Mapping,我有下面列出的映射 当我更新分离的类别项目(不包含任何Hibernate类,因为它来自dto转换器)时,我注意到Hibernate将首先删除所有雇主工资实例(集合链接),然后逐个插入所有雇主工资条目:( 我知道它必须删除然后插入所有条目,因为它已完全分离 但是,我不明白的是,为什么Hibernate不通过批量插入插入所有条目?。。 也就是说:在一个SQL语句中插入所有雇主工资条目 如何告诉Hibernate使用大容量插入?(如果可能)。 我尝试使用以下值,但没有发现任何差异: hibernate

我有下面列出的映射

当我更新分离的类别项目(不包含任何Hibernate类,因为它来自dto转换器)时,我注意到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>

...
...

批量插入-是用于快速插入的特定本机方式,通常用于本机外部工具,如用于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();
Session Session=sessionFactory.openSession();
事务tx=会话.beginTransaction();
对于(int i=0;i