生成id

来源:互联网 发布:链表java 编辑:程序博客网 时间:2024/05/26 12:04
 public void saveHoliday(TblLegalHoliday holiday) {
  final String seqScript = "select " + Constant.SeqConstant.SEQ_HR
    + ".nextval from dual";
  Object numObj = getHibernateTemplate().execute(new HibernateCallback() {
   public Object doInHibernate(Session session)
     throws HibernateException, SQLException {
    return session.createSQLQuery(seqScript).uniqueResult();
   }
  });
  holiday.setId((BigDecimal) numObj);
  this.getHibernateTemplate().save(holiday);
 }