Announcement Announcement Module
Collapse
No announcement yet.
When does the spring HibernateTransactionManager require exclusive access to the db? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • When does the spring HibernateTransactionManager require exclusive access to the db?

    I am a bit of the newb concerning transaction management, but could use clarification on an aspect of how it functions-

    When does the org.springframework.orm.hibernate3.HibernateTransa ctionManager require exclusive access to the db?

    Should I with a normal configuration be able to run two different applications against the same database or are some adjustments required?

    I ask because when I execute junit tests from maven against a DB that is in use by a spring application, I get errors regarding "could not get lock on table."

    Lets say I have a spring application and I would like to, for whatever perverse reason, run a seperate grails app using the same database as the standalone spring application, what sort of adjustments would I need to make?

    Advice much appreciated!

    -JC

  • #2
    Spring transaction manager does not put any locks on its own.
    It only starts and ends (commit/rollback) transaction. All locks are put by your own application code. So look into your code and try to figure out when and why you lock the whole table (as I assume from your "could not get lock on table." message.

    And sure no exclusive acces to Db is required by transaction manager. It is your appplication that may need such access (and not to DB but to single tables) if designed badly.

    Regards,
    Oleksandr
    Originally posted by jcspring View Post
    I am a bit of the newb concerning transaction management, but could use clarification on an aspect of how it functions-

    When does the org.springframework.orm.hibernate3.HibernateTransa ctionManager require exclusive access to the db?

    Should I with a normal configuration be able to run two different applications against the same database or are some adjustments required?

    I ask because when I execute junit tests from maven against a DB that is in use by a spring application, I get errors regarding "could not get lock on table."

    Lets say I have a spring application and I would like to, for whatever perverse reason, run a seperate grails app using the same database as the standalone spring application, what sort of adjustments would I need to make?

    Advice much appreciated!

    -JC

    Comment


    • #3
      If I am not explicitly locking tables, what should I be looking for? My configuration is very straightforward lacking in complex operations, each DAO does nothing more then save/update/delete/find/load.

      My hibernate configuration is:

      <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
      <property name="dataSource" ref="dataSource"/>
      <property name="mappingLocations">
      <list>
      <value>classpath*:com/mnu/model**/*.hbm.xml</value>
      </list>
      </property>
      <property name="hibernateProperties">
      <props>
      <prop key="hibernate.dialect">${hibernate.dialect}</prop>
      <prop key="hibernate.show_sql">${hibernate.show.sql}</prop>
      <prop key="hibernate.generate_statistics">${hibernate.ge nerate_statistics}</prop>
      <prop key="hbm2ddl.auto">${hbm2ddl.auto}</prop>
      </props>
      </property>
      </bean>

      <bean id="transactionManager" class="org.springframework.orm.hibernate3.Hibernat eTransactionManager">
      <property name="sessionFactory" ref="sessionFactory"/>
      </bean>

      That said, how should one architect their applications to anticipate multiple transactionmanagers accessing the same database?

      Comment


      • #4
        It has nothing to do with your configuration, but with your code.
        and concerning
        That said, how should one architect their applications to anticipate multiple transactionmanagers accessing the same database?
        Transaction manager does not access database in some special manner, it just executes beginTransaction/commit/rollback calls on database connections (the same way as application do in absence of transaction manager). So no special precautions, configurations ... are needed.

        And as you using hibernate which defaults to optimistic locking no long-liver lock should b held (i.e. locks appears only in the moment of DML-operations and operation are delayed as far as possible). Please, post your stack trace and piece of code that causes that trace.

        Regards,
        Oleksandr

        Comment

        Working...
        X