problems with defer session close

  • Nobody/Anonymous


    I am using hivetranse 0.5 and hibernate 3.11 and have difficulties with the open session in view setup. In particular I notice that for each method invocation in my dao a new session is opened. That is for methods, which are intercepted by the transaction interceptor.

    By looking at the code in TransactionHibernateService I noticed that each time that createTransaction is invoked, a new SessionsRepositoryImpl is returned, which in turn will then always open a new session when it's getSession method is called. Is that the expected behaviour?

    Btw, by browsing through the code I noticed that in "protected TransactionException    openTransaction(TransactionEntry entry)" in the SessionsRepositoryImpl the TransactionException is thrown and not returned. Considering the method signature that's probably a bug.

    • Nobody/Anonymous


      As I far as I can understand the problem you describe, this seems not related to the "defer session close" settings.

      What I guess is that you only put the TransactionInterceptor at the level of your DAO, in such case, the behavior (exactly the same as in an EJB container) is that every method call from an other service (that does not have TransactionInterceptor) will create a new transaction.

      If you want several DAO consecutive calls to be in the same transaction then you must put the TransactionInterceptor (along with the correct transaction demarcation) at the level of a higher-level service that will call all your DAO methods in sequence.

      About your discovery in SessionRepositoryImpl.openTransaction() method, yes as far as I can tell, this seems a bug to me, thank you for having reported it!



    • Zubairov Renat

      Zubairov Renat - 2006-03-16

      +1 to this bug report. I have the same problem and found the same things in the source code. Is there any ideas how to fix it?

    • Zubairov Renat

      Zubairov Renat - 2006-03-16

      One quick and dirty possible solution could be to use monostate pattern in SessionRepositoryImpl.
      I've replaced local hashmap with a static instance of a synchronized hashmap

      private static final Map    _sessions = Collections.synchronizedMap(new HashMap());

      It works for now. Don't know about possible consiquences.

    • Jean-Francois Poilpret

      Hello Renat,

      unfortunately your solution is not safe as far as I can tell: it would break the transaction demarcation system of HiveTranse: if you start to use the "REQUIRES_NEW" demarcation, you will see problems coming...

      Until now, I could not see what was described in the original mail as a bug. I am curious to know:
      - what you want to achieve
      - how you configured your services (including your DAOs)
      - what exactly happens that seems not correct to you
      - and what's the relationship with the "open session in view" pattern?

      In addition, if you could provide one, I would gladly accept a Test Case that shows the problem so that I can work on it if it is a bug, or suggest a different way if it is not.

      If this is a bug it will be fixed for the next release (0.6.0) of hivetranse (soon I hope, I am finishing the last details).




Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks