首页 新闻 赞助 找找看

hibernate批量更新带有外键的 对象。

0
悬赏园豆:5 [已关闭问题] 关闭于 2016-06-01 20:42
这是我从hibernate 的api'上看到的。但是需要保存  的 对象 有几个字段是外键,需要从数据库获取。
必须下面的红色代码。特别费时间。求没有没其他解决办法


Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction();    for ( int i=0; i<100000; i++ ) {         Customer customer = new Customer(.....);
      customer.country=countryService.getCountry('countryId');
        session.save(customer);         if ( i % 20 == 0 ) { //20, same as the JDBC batch size            //flush a batch of inserts and release memory:            session.flush();            session.clear();     } }     tx.commit(); session.close();
康大头的主页 康大头 | 初学一级 | 园豆:25
提问于:2016-02-18 14:16
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册