Home Hibernate 5.2.9.Final cache not updated
Reply: 0

Hibernate 5.2.9.Final cache not updated

greengold
1#
greengold Published in 2018-01-11 15:32:11Z

I have a service (which I for some reason call controller) that is injected into the Jersey resource method.

@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); gets an Entity object from the database.

@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();
    }
}

However When I do second request to my API, I see state of this entity object unchanged, that means the same as before the logic above occoured. In DB there is still changed status. After the api service restart, I will get the entity in the correct state.

As I understand it, Hibernate uses it's L2 cache for the managed objects. So can you, please point me to what I am doing wrong here? Obviously, I need to get cached entity with the changed state without service restart and I would like to keep entities attached to the persistence context for the performance reasons.

Now, can you tell me what I am In the logic I am making some changes to this object. After the completition of the changeDocState method, the state is properly changed and persisted in the database.

Thanks for the answers;

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.323515 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO