我有以下方法从数据库表中提取数据
public User getNextUser() {
final EntityManager em = getEntityManagerFactory().createEntityManager();
final String sql = "UPDATE user " +
"SET processing = TRUE " +
"WHERE id = (" +
"SELECT id " +
"FROM user " +
"WHERE processing = FALSE " +
"LIMIT 1 FOR UPDATE) " +
"RETURNING *";
final Query query = em.createNativeQuery(sql, User.class);
User result = null;
try {
List userList = query.getResultList();
if (!userList.isEmpty()) {
result = (User) userList.get(0);
}
} finally {
em.close();
}
return result;
}
如何将此本机查询转换为Hibernate查询(不使第二级缓存无效)?我读过相当于
的内容SELECT ... FOR UPDATE
在Hibernate中,可以通过
实现PESSIMISTIC_WRITE