Hibernate一括更新(キャッシュなしでデータベースをリアルタイムで挿入)
コードは次のとおりです.
StringBuffer quyHql = new StringBuffer();
quyHql.append(" from User where userId=? and status=?");
// session
StatelessSession session = getSessionFactory().openStatelessSession();
Transaction tx = session.beginTransaction();
ScrollableResults list = session.createQuery(quyHql.toString()).setLong(0, id)
.setString(1, GlobalConstants.DIC_VALUE_VALID_VALIDITY).scroll(ScrollMode.FORWARD_ONLY);
try {
while (list.next()) {
User user= (User) list.get(0);
user.setStatus(GlobalConstants.DIC_VALUE_VALID_INVALIDITY);//
session.update(user);//実行が完了すると、すぐに有効になります}}catch(Exception e){logger.info("ロールバック");tx.rollback();tx.commit();session.close();