"SET c.privateMessageFolderId = :privateMessageFolderId, c.isTrash = false " +
"where c.privateMessageId IN (:privateMessageIds) ";
Object idf = PersistenceSessionUtil.createSession();
EntityManager session = PersistenceSessionUtil.getSession();
EntityTransaction tx = session.getTransaction();
tx.begin();
Query query = session.createQuery(hql);
query.setParameter("privateMessageFolderId", privateMessageFolderId);
query.setParameter("privateMessageIds", privateMessageIds);
int updatedEntities = query.executeUpdate();
//Refresh the Entities in the Cache as Hibernate will not do it!
for (Long privateMessageId : privateMessageIds) {
String hqlSel = "select c from PrivateMessages c " +
"where c.privateMessageId = :privateMessageId ";
Query querySel = session.createQuery(hqlSel);
querySel.setParameter("privateMessageId", privateMessageId);
PrivateMessages privateMessages = null;
try {
privateMessages = (PrivateMessages) querySel.getSingleResult();
} catch (NoResultException ex) {
}
if (privateMessages != null) {
session.refresh(privateMessages);
}
}
tx.commit();
PersistenceSessionUtil.closeSession(idf);
return updatedEntities;
} catch (Exception e) {
log.error("[updatePrivateMessagesReadStatus]",e);
}