Announcement Announcement Module
Collapse
No announcement yet.
Hibernate thread local session without a transaction manager Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate thread local session without a transaction manager

    Hi,

    I want to copy some data from one database to another one.
    I am using hibernate so I have two sessionfactory : one for each database.
    I need transaction on the second one because I write some data but I do not need transaction on the first one because I am only reading data in it.

    My problem is that without transaction management on the first database, I cannot reuse the same session accross multiple dao calls (and I cannot have my session open after a dao call). So in my application I have some lazy initialisation exceptions.

    I want to know the best way to keep my session opened during one service call on the first database.

    Maybe it is better to create a transaction manager on the read-only database. But if I do that I cannot use the standard transaction declaration techniques

    I have one idea : create my own custom transactionmanager that encapsulates two hibernatetransactionmanager : is it something realistic ? What other classes do I have to implement : transactionstatus, other ones ?

    Thanx

    Seb

  • #2
    You can configure a HibernateTransactionManager for your destination database, and a HibernateInterceptor for the readOnly Database, then use the later as a postInterceptor within your service:
    Code:
      <bean id="transactionManager" ...
      <bean id="hibernateInterceptor" ...
    
      <bean id="myService" class="o.s.t.i.TransactionProxyFactoryBean">
        <property name="daoOne" ...
        <property name="daoTwo" ...
        <property name="transactionManager">
          <ref local="transactionManager"/>
        </property>
        <property name="postInterceptors">
          <list>
            <ref local="hibernateInterceptor"/>
          <list>
        </property>
        ...
      </bean>
    HTH

    Comment

    Working...
    X