1、获取数据库连接
Connection conn=SessionFactoryUtils.getDataSource(getSessionFactory()).getConnection();
2、获取sequence下一个值
Session session = null;
session = this.getSession();
// 查询下一个sequenceName的值
sqlBuffer.append("select ").append(sequenceName).append(".nextval as nextval from dual");
List list = session.createSQLQuery(sqlBuffer.toString()).list();
if (list.size() == 1) {
return list.get(0) + "";
} else {
// 手动抛出异常
StringBuffer ex = new StringBuffer();
ex.append("获取名字为:");
ex.append(sequenceName);
ex.append("码异常.");
ex.append("SQL=");
ex.append(sqlBuffer.toString());
throw new Exception(ex.toString());
}