标签:des c style class blog code
批量处理数据是指在一个事务中处理大量数据.
在应用层进行批量操作, 主要有以下方式:
public class HibernateTest { private SessionFactory sessionFactory; private Session session; private Transaction transaction; @Before public void init(){ Configuration configuration = new Configuration().configure(); ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()) .buildServiceRegistry(); sessionFactory = configuration.buildSessionFactory(serviceRegistry); session = sessionFactory.openSession(); transaction = session.beginTransaction(); } @After public void destroy(){ transaction.commit(); session.close(); sessionFactory.close(); } @Test public void testBatch(){ session.doWork(new Work() { @Override public void execute(Connection connection) throws SQLException { //通过 JDBC 原生的 API 进行操作, 效率最高, 速度最快! } }); } }
hibernate 批量处理数据,布布扣,bubuko.com
标签:des c style class blog code
原文地址:http://blog.csdn.net/qilixiang012/article/details/28044665