Exemplo n.º 1
0
 /** delete data by raw SQL */
 public void updateBySQL(String sql) {
   Session session = HibernateUtils.getSession();
   try {
     sql = sql + conditionBuilder.build();
     this.queryBuilder.buildSQLQuery(session, sql).executeUpdate();
   } catch (Throwable e) {
     LOGGER.error("fail to update, sql: {}, list: {}", sql, e);
     throw e;
   } finally {
     HibernateUtils.commit(session); // ensure session is closed
   }
 }
Exemplo n.º 2
0
 /**
  * method to execute update
  *
  * @param clazz class to update
  * @param setClause such as 'username=:username,password=:password' and so on
  */
 public void update(Class<?> clazz, String setClause) {
   Session session = HibernateUtils.getSession();
   String hql =
       "UPDATE " + clazz.getSimpleName() + " SET " + setClause + " " + conditionBuilder.build();
   try {
     this.queryBuilder.buildQuery(session, hql).executeUpdate();
   } catch (Throwable e) {
     LOGGER.error("fail to update, hql: {}, info: {}", hql, e);
     throw e;
   } finally {
     HibernateUtils.commit(session); // ensure session is closed
   }
 }