try {
//pTemp = new SchemaExport(cfg);
//pTemp.create(true, true);
sf = cfg.buildSessionFactory();
s = sf.openSession();
} catch (HibernateException e) {
e.printStackTrace();
log.error("Hibernate 错误" + e);
return;
}
try {
log.info("Open Session OK");
long start = System.currentTimeMillis();
for (int i = 0; i < 10; i++) {
UserInfo message = new UserInfo();
message.setId(String.valueOf(i));
message.setUserName(String.valueOf(i));
message.setPassword(String.valueOf(i));
try {
s.save(message);
s.flush();
//s.evict(message);
} catch (HibernateException e4) {
e4.printStackTrace();
log.error("Hibernate Insert 错误" + e4);
return;
}
}
long end = System.currentTimeMillis();
log.info(new Long(end - start));
}
catch(Exception e){
e.printStackTrace();
log.error("Hibernate Insert 错误" + e);
return;
}
finally {
try {
s.close();
} catch (HibernateException e4) {
e4.printStackTrace();
log.error("Hibernate Close 错误" + e4);
}
}
}
}
本文地址:http://com.8s8s.com/it/it16701.htm