当前位置:K88软件开发文章中心编程语言SQLHibernate → 文章内容

Hibernate 批处理

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-18 8:34:29

owable ex) { System.err.println("Failed to create sessionFactory object." + ex); throw new ExceptionInInitializerError(ex); } ManageEmployee ME = new ManageEmployee(); /* Add employee records in batches */ ME.addEmployees( ); } /* Method to create employee records in batches */ public void addEmployees( ){ Session session = factory.openSession(); Transaction tx = null; Integer employeeID = null; try{ tx = session.beginTransaction(); for ( int i=0; i<100000; i++ ) { String fname = "First Name " + i; String lname = "Last Name " + i; Integer salary = i; Employee employee = new Employee(fname, lname, salary); session.save(employee); if( i % 50 == 0 ) { session.flush(); session.clear(); } } tx.commit(); }catch (HibernateException e) { if (tx!=null) tx.rollback(); e.printStackTrace(); }finally { session.close(); } return ; }}编译和执行这里是编译和运行以上提及的应用程序的步骤。确保你已经在处理编译和运行前已经正确设置了 PATH 和 CLASSPATH。 如上面解释的那样创建 hibernate.cfg.xml 配置文件。如上面显示的那样创建 Employee.hbm.xml 映射文件。如上面显示的那样创建 Employee.java 源文件并编译。如上面显示的那样创建 ManageEmployee.java 源文件并编译。执行 ManageEmployee 二进制代码来运行可以在 EMPLOYEE 表单中创建 100000 个记录的程序。

上一页  [1] [2] 


Hibernate 批处理