What's the difference of EntityManager (setHint) Read-Only and Session Read-Only?

Viewed 2653

I'm trying to load some entities as read-only, I noticed that I have some options to do that, like @Immutable and also read-only in query.

My main question is what's the difference between setHint:

    getEntityManager().createQuery("SELECT p FROM Post p").setHint(QueryHints.READ_ONLY, true).getResultList();

And setReadOnly:

    Query query = session.createQuery("SELECT p FROM Post p");
    query.setReadOnly(true);
    query.list();

Are they the same thing?

1 Answers

same thing: the hibernate implementation of javax.persistence.TypedQuery.setHint(String, Object)(org.hibernate.jpa.spi.AbstractQueryImpl.setHint(String, Object)) is calling indirectly the org.hibernate.Query.setReadOnly(boolean):

org.hibernate.Query.setReadOnly(boolean)
called by org.hibernate.jpa.internal.QueryImplapplyReadOnlyHint(boolean)
called by org.hibernate.jpa.spi.BaseQueryImplsetHint(String, Object)
called by org.hibernate.jpa.spi.AbstractQueryImpl.setHint(String, Object)
Related