java二级缓存如何影响hibernate中的批处理?
假设我有以下批插入代码
for (int i = 0; i < 1_000_000; i++) {
final Book book = new Book("9781617291999", "Java 8 in Action", new Date());
session.save(book);
if(i % 50 == 0) { // 50 is the batch_size
session.flush();
session.clear();
}
}
我指的那本书说,需要使用session.setCacheMode(CacheMode.IGNORE)
为book实体禁用二级缓存
使批量插入生效
由于session.flush
和session.close
主要影响一级缓存,因此启用/禁用二级缓存如何影响批量插入过程
共 (0) 个答案