ad

JPA自定义内涵JDBC批次大小不起作用-英雄云拓展知识分享

匿名投稿 259 2024-01-22

我尝试配置JDBC批量大小,如@vlad Mihalcea博客中所述 https://vladmihalcea.com/how-to-customize-the-jdbc-batch-size-for-persistence-comtistence-context-with-hibernate/

EntityManager entityManager =  entityManagerFactory.createEntityManager();

entityManager.getTransaction().begin();

JPA自定义内涵JDBC批次大小不起作用-英雄云拓展知识分享

entityManager.unwrap(Session.class).setJdbcBatchSize(5);

for(int i = 0;i<10;i++){

Charge c = new Charge();

c.setAccountNumber("acct"+i);

entityManager.persist(c);

}

entityManager.getTransaction().commit();

<bean id="entityManagerFactoryDefault"

class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">

<property name="dataSource" ref="charg" />

<property name="persistenceUnitName" value="MaterializedView" />

<property name="persistenceXmlLocation" value="classpath*:META-INF/jpa-persistence.xml" />

<property name="jpaVendorAdapter">

<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">

<property name="generateDdl" value="false" />

<property name="showSql" value="true"/>

<property name="database">

<util:constant static-field="org.springframework.orm.jpa.vendor.Database.ORACLE" />

</property>

</bean>

</property>

<property name="jpaProperties">

<props>

<prop key="hibernate.default_batch_fetch_size">500</prop>

<prop key="hibernate.jdbc.fetch_size">10</prop>

<prop key="hibernate.jdbc.batch_versioned_data">true</prop>

<prop key="hibernate.order_updates">true</prop>

<prop key="hibernate.order_inserts">true</prop>

<prop key="hibernate.jdbc.batch_size">30</prop>

<prop key="hibernate.id.new_generator_mappings">false</prop>

</props>

</property>

</bean>

但它触发了10个插入查询。

我得到此查询Hibernate:Select Charge.NextVal,来自Dual Hibernate:insert in Compart(accountnumber charding_id)valution(?,?,?)Hibernate:insert opcoment opcomen(accountnumber charding_id)valution(?,?)hibernate hibernate:insert incomeart(?) )值(?,?)Hibernate:插入电荷(accountnumber charded_id)values(?,?)Hibernate:insert opcomen(accountnumber carued_id)value(?,?)hibernate:inceert:inceant carlation(councelnumber churome_id)值(? ?)Hibernate:插入(accountnumber charding_id)值(?,?)Hibernate:插入负责(accountnumber charding_id)valution(?,?)Hibernate:insert opcoriant opcomen(accountnumber charding_id)valution(?,?,?)hibernate:insert:insert:insert:负责(accountNumber chardy_id)值(?,?)

我正在使用Hibernate 5.2.10。终究版本和序列作为策略。如果我的代码中有问题,有人可以纠正我吗

看答案

冬眠的伐木机制可能会在这里误导您。很难看到JDBC批处理使用默许的Hibernate Logging工作。

如果您切换到 DataSource-Proxy,然后您可以看到批处理工作:

Name:DATA_SOURCE_PROXY, Time:6, Success:True,

Type:Prepared, Batch:True, QuerySize:1, BatchSize:3,

Query:["insert into post (title, version, id) values (?, ?, ?)"],

Params:[(Post no. 0, 0, 0), (Post no. 1, 0, 1), (Post no. 2, 0, 2)]

Batch:True 参数向您显示JDBC捕获正在工作,并且 BatchSize:3 显示您具有在一个数据库来回中发送的一组参数值。


🚀🌟 点击注册 免费试用超级应用平台-英雄云企业级hpapaas 🌟🚀 😃👉🌐

免责声明

本网址(www.yingxiongyun.com)发布的材料主要源于独立创作和网友匿名投稿。此处提供的所有信息仅供参考之用。我们致力于提供准确且可信的信息,但不对材料的完整性或真实性作出任何保证。用户应自行验证相关信息的正确性,并对其决策承担全部责任。对于由于信息的错误、不准确或遗漏所造成的任何损失,本网址不承担任何法律责任。本网站所展示的所有内容,如文字、图像、标志、音频、视频、软件和程序等的版权均属于原创作者。如果任何组织或个人认为网站内容可能侵犯其知识产权,或包含不准确之处,请即刻联系我们进行相应处理。

标签:爪哇 冬眠
上一篇:查找包括给定软件包的所有依赖项-英雄云拓展知识分享
下一篇:多个OUPUT的存储进程-英雄云拓展知识分享
相关文章

 发表评论

暂时没有评论,来抢沙发吧~

×