English 中文(简体)
Spring: @transactional with Read only=true not calls conn.setReadOnly(true)
原标题:Spring: @Transactional with readonly=true not call conn.setReadOnly(true)

我用<代码>@transactional对我的服务方法做了说明。

自那天春天起,它就没有使用单套管连接驱动器的方法。 我能做些什么?

由于我将采用主人奴役的复制方式,支那群人将使用只读的旗帜,把 que带向主人或奴隶。

问题回答

第一,你只应当把“......”改为“......”。 只有在贵邮联交易方式是RESOURCE-LOCAL时,才悬挂日本外行的国旗。 如果是联合信托机构,那么你就不应改变这种情形,因为你不会在交易中获得相同的支用连接点(JTA——而不是Hibernate——将确保交易行为)。 在进行商业交易时,自由会首次打开一条支线,并在交易期间保持这一连接。

1. JPA

If you re using JPA with Hibernate as the provider, you can add this extra behaviour by providing your own implementation of JpaDialect to the EMF definition. When using Hibernate, you will usually inject a HibernateJpaDialect.

JpaDialect界面有getJdbcConnection(em,Only)方法,可回收实际的JDBC链接。 交易开始时,Jpa TransactionManager会援引这种方法。 缺席,HibernateJpaDialect并不改变因这一JTA/RESOURCE-LOCAL双重性而重新划定的交接线,但如果你只管理当地交易,你可以这样做。

实现以下目标:

<>Resource LocalReadOnlyAwareHibernateJpaDialect

public class ResourceLocalReadOnlyAwareHibernateJpaDialect extends HibernateJpaDialect {
  public ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly) throws PersistenceException, SQLException {
    Session session = getSession(entityManager);
    return new HibernateReadOnlyAwareConnectionHandle(session, readOnly);
  }

  // this is similar to spring s HibernateJpaDialect own internal class,
  // except for the readonly flags.
  private static class HibernateReadOnlyAwareConnectionHandleimplements ConnectionHandle {
    private final Session session;
    private final boolean readOnly;
    private static volatile Method connectionMethod;

    public HibernateConnectionHandle(Session session, boolean readOnly) {
      this.session = session;
      this.readOnly = readOnly;
    }

    public Connection getConnection() {
      try {
        if (connectionMethod == null) {
          // reflective lookup to bridge between Hibernate 3.x and 4.x
          connectionMethod = this.session.getClass().getMethod("connection");
        }
        Connection con = (Connection) ReflectionUtils.invokeMethod(connectionMethod, this.session);
        con.setReadOnly(this.readOnly);
        return con;
      } catch (NoSuchMethodException ex) {
        throw new IllegalStateException("Cannot find connection() method on Hibernate session", ex);
      }
    }

    public void releaseConnection(Connection con) {   // #1
      con.setReadOnly(false);
      JdbcUtils.closeConnection(con);
    }
  }

}

附注1:将直线旗帜改为在连接前伪造(实际上不是真正的<条码>连接>,即电话,而只是释放与集合的联系)。 不清楚这一方法究竟是什么触发因素,但认为将直线的国旗重新定在改变的同一类别是正当的。

2. Pure Hibernate

首先,确保<代码>Hibernate TransactionManager.prepareConnection仍然有效。

然后,我不敢肯定要做些什么。 你们必须去掉星号<>Hibernate TransactionManager.isSameConnectionForEntireSession(>:如果方法回归真实,将援引联系。

如果没有,你可以改变自由联系。 ReleaseModeating to ON_CLOSE (hibernate property hibernate.transaction.auto_close_session=true, which was the Object before Hibernate 3.1), or overwHibernate TransactionManager.isameConnectionForEntireSession(), in order to 所有这些返回都是真实的(关于HiberntransactionManager的评论,这被认为是安全的)。 两者都是“预谋”的,但都应当是独立的AFAIK。 实际上,我想Hibernate TransactionManager.isSameConnectionForEntireSession()。 应加以修改,以恢复欧空局网站。 词汇 释放方式: 管理人员,清理工作在交易完成后会发生,从而不会改变解放行为。





相关问题
Multiple Hibernate instances using C3P0

I am facing a weird problem and it seems to be c3p0 related. I am starting two instances of an app in the same java vm which interact with each other. After some operations "APPARENT DEADLOCK" ...

Hibernate vs Ibatis caching

We can speed up a hibernate app easyly with 2nd level cache using infinispan or ehcache/terracotta,... but ibatis only have a simple interface to implement for caching. And hibernate knows more ...

Using annotations to implement a static join in hibernate

I m relatively new to hibernate and was wondering if someone could help me out. While I have no issues implementing a normal join on multiple columns in hibernate using the @JoinColumns tag, I m ...

Hibernate query with fetch question

I have a 2 entities in a One-To-Many relationship: OfficeView.java: public class OfficeView implements java.io.Serializable { private Integer officeId; private String addr1; private ...

hibernate interceptors : afterTransactionCompletion

I wrote a Hibernate interceptor : public class MyInterceptor extends EmptyInterceptor { private boolean isCanal=false; public boolean onSave(Object entity, Serializable arg1, Object[] arg2, String[]...

How to prevent JPA from rolling back transaction?

Methods invoked: 1. Struts Action 2. Service class method (annotated by @Transactional) 3. Xfire webservice call Everything including struts (DelegatingActionProxy) and transactions is configured ...

Hibernate/GORM: collection was not processed by flush()

I have an integration test in my Grails application that fails when I try to save an entity of type Member invitingMember.save(flush: true) This raises the following exception org.hibernate....

Hibernate Criteria API equivalent for "elements()"

Is it possible to implement the following query using Criteria API? select order from ORDER as order,ITEM as item where item.itemID like ITM_01 and item in elements(order.items)