日期:2014-05-20 浏览次数:20722 次
public Integer batchSave(Session session, String insertSql, String tableName){ Transaction tx = session.beginTransaction(); Integer result = -1; String queryString = "SELECT last_insert_id() FROM "+tableName+" LIMIT 1;"; try { tx.begin(); result = [color=#FF0000]session.createSQLQuery(insertSql).executeUpdate();[/color] session.flush(); tx.commit(); if(result > 0) return(new Integer([color=#FF0000]session.createSQLQuery(queryString).list()[/color].get(0).toString())); } catch (DataAccessException e) { e.printStackTrace(); if (tx != null) { tx.rollback(); } } return null; }