在我的休眠属性中 30 在我的代码中,我做了类似的事情final StatelessSession sSession = sessionFactory.openStatelessSession();try { sSession.connection().setAutoCommit(false);} catch (final SQLException se) { // log a message}final Transaction tx = sSession.beginTransaction();try{ for ( some loop ) { Customer customer = new Customer(.....); sSession.insert(customer); /* Do we need to flush a stateless session? It doesn't have methods for it if ( i % 30 == 0 ) { //30, same as the JDBC batch size //flush a batch of inserts and release memory: sSession.flush(); sSession.clear(); } */ } //sSession.flush();// Do we need to flush a stateless session? It doesn't have methods for it //sSession.clear();} finally{ tx.commit(); sSession.close();}我的Pojo具有以下内容@Id//@GeneratedValue(strategy = GenerationType.AUTO)@Column(name = "ID", nullable = false, unique = true)private Long id;但是,当我更改批次大小时,它似乎并没有影响整体运行时间。我如何验证它确实在工作?谢谢! (adsbygoogle = window.adsbygoogle || []).push({}); 最佳答案 注释掉session.flush();,看看20次循环迭代后是否插入了任何东西更新:更新后的问题注释//@GeneratedValue(strategy = GenerationType.AUTO)应该退回到默认值,即AFAIK身份尝试使用@TableGenerator(name="TABLE_GEN", table="SEQUENCE_TABLE", pkColumnName="SEQ_NAME", valueColumnName="SEQ_COUNT", pkColumnValue="EMP_SEQ")@GeneratedValue(strategy=GenerationType.TABLE, generator="TABLE_GEN") (adsbygoogle = window.adsbygoogle || []).push({}); 10-06 09:31