EntityManager(setHint)只读和会话只读有什么区别?

时间:2018-09-05 12:18:13

标签: hibernate jpa

我正在尝试将某些实体加载为只读,我注意到我可以执行一些选择,例如@Immutable以及查询中也是只读的。

我的主要问题是setHint和有什么区别?

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

然后setReadOnly:

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

他们是同一回事吗?

1 个答案:

答案 0 :(得分:0)

同一件事: javax.persistence.TypedQuery.setHint(String,Object)(org.hibernate.jpa.spi.AbstractQueryImpl.setHint(String,Object))的休眠实现正在间接调用org.hibernate.Query.setReadOnly(boolean):< / p>

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)