Hibernate 5.2.9.Final缓存未更新

时间:2018-01-11 15:32:12

标签: java hibernate jpa transactions

我有一个注入Jersey资源方法的服务(我出于某种原因调用控制器)。

@Named
@Transactional
public class DocCtrl {
   ...

public void changeDocState(List<String> uuids, EDocState state, String shreddingCode) throws DatabaseException, WebserviceException, RepositoryException, ExtensionException, LockException, AccessDeniedException, PathNotFoundException, UnknowException {
        List<Document2> documents = doc2DAO.getManyByUUIDs(uuids);
        for (Document2 doc : documents) {
            if (EDocState.SOFT_DEL == state) {
                computeShreddingFor(doc, shreddingCode); //here the state change happens and it is persisted to db
            }

            if (EDocState.ACTIVE == state)
                unscheduleShredding(doc);
        }
    }
}

doc2DAO.getManyByUUIDs(uuids);从数据库中获取Entity对象。

@Repository
public class Doc2DAO {
@PersistenceContext(name = Vedantas.PU_NAME, type = PersistenceContextType.EXTENDED)
    private EntityManager entityManager;

public List<Document2> getManyByUUIDs(List<String> uuids) {
        if (uuids.isEmpty())
            uuids.add("-3");

        TypedQuery<Document2> query = entityManager.createNamedQuery("getManyByUUIDs", Document2.class);
        query.setParameter("uuids", uuids);
        return query.getResultList();
    }
}

然而,当我向我的API发出第二个请求时,我看到此实体对象的状态未更改,这意味着与上面的逻辑之前相同。 在DB中,状态仍然存在变化。 api服务重启后,我将使实体处于正确的状态。

据我所知,Hibernate使用它的L2缓存来管理对象。 所以,请指点我在这里做错了什么?显然,我需要在没有服务重启的情况下获得具有已更改状态的缓存实体,并且出于性能原因,我希望将实体附加到持久性上下文。

现在,你能告诉我我的意思吗? 在逻辑中,我正在对这个对象进行一些更改。完成changeDocState方法后,状态会在数据库中正确更改并保留。

感谢您的回答;

0 个答案:

没有答案