Skip to main content

Posts

Showing posts from May, 2018

How to batch INSERT and UPDATE statements with Hibernate

Courtesy: VLAD MIHALCEA Introduction JDBC  has long been offering support for  DML  statement batching. By default, all statements are sent one after the other, each one in a separate network round-trip. Batching allows us to send multiple statements in one-shot, saving unnecessary socket stream flushing. Hibernate hides the database statements behind a transactional  write-behind abstraction layer . An intermediate layer allows us to hide the JDBC batching semantics from the persistence layer logic. This way, we can change the JDBC batching strategy without altering the data access code. Configuring Hibernate to support JDBC batching is not as easy as it should be, so I’m going to explain everything you need to do in order to make it work. Testing time We’ll start with the following entity model: The  Post  has a one-to-many association with the  Comment  entity: 1 2 3 4 5 @OneToMany (    ...