Java – spring hibernate JDBC batch size
I have several scenes. I think it's a little unclear from hibernate documentation
Data class:
class HibernateDao { // ... @Transactional public void store(List<Object> batch) { for(Object o : batch) { hibernate.store(o); } } }
Scenario 1
hibernate.jdbc.batch_size = 1
Q1: call store (..) with a collection of 10 items What will happen? Will there be 10 transactions or only one?
Scenario 2
hibernate.jdbc.batch_size = 10
Q2: call store (..) with a collection of 1 item What will happen? Regardless of batch_ What about the size attribute and whether it will be written to backing storage immediately?
From hibernate documents:
Question 3: what is classified as an identification identifier generator, using the annotation @ ID and @ generatedvalue (strategy = generationtype. Auto)?
Solution
This is spring transaction specific, but in the case of hibernate, if you use a session and a "transaction", it will wait until "flush" or "commit" actually performs the operation So, a deal
Not right away The same content in the previous response applies to this: unless you explicitly require "Refresh", hibernate will perform the operation during the submission phase
Hibernate cannot predict any ID as ID. for example, identity (such as sequence, but for T-SQL database), automatic increment, sequence... The reason is very simple: Hibernate does not know what the generated ID of each batch entity is. Therefore, the inserted entity state is different from the previous state Hibernate handles the conventional scheme by calling the JDBC method of "getgeneratedkeys", which allows it to synchronize the data in the database with the data in its session, but it is impossible to synchronize the batch
If hibernate does know the ID of the entity (i.e. assigned, Hilo, UUID,...), it can safely execute batch processing