Is it ok to use DataSourceTransactionManager for ORM persistence instead of HibernateTransactionManager?

允我心安 提交于 2019-12-21 01:48:26

问题


I am debugging our webapp. It is configured to create a DataSourceTransactionManager bean and also a HibernateTransactionManager bean on startup. This is not intentional but is caused by a 3rd party dependency. The effect appears to be benign. What I'm seeing via debugging is that when we persist an object via a Hibernate based DAO - the DataSourceTransactionManager is invoked and not the HibernateTransactionManager (the beans both are called 'transactionManager'). The Spring Javadoc implies (I think, re-reading it now) this is fine for local resources - which is our situation. I.e. its not a distributed JTA based environment.

My question is - is there any negative impact of not using the HibernateTransactionManager for ORM based persistence. I can change the config to make the HibernateTransactionManager be used via a qualifier on the @Transactional annotation on our DAOs.

Things are working fine in simple unit test, integration test setup but I am more concerned about scaling to full production volumes when we'll have thousands of users and a high level of concurrency.

TIA, hope this isn't too obscure.

Spring 3.0.x BTW.

This is in the Spring 3.1 docs.

Sec 11.9 "Solutions to Common Problems".

Use the correct PlatformTransactionManager implementation based on your choice of transactional technologies and requirements.


回答1:


This would strike me as wrong and will cause problems. Without the hibernate txn manager all calls made to HibernateOperations will be outside a transaction and on a separate session, possibly using auto-commit. So it might appear that everything is fine when an error occurs you may find changes you would expect to be rolled-back aren't.

Try the following to check

  • begin tran
  • save something
  • throw exception
  • commit

Check whether the 'something' appears in the DB or not.

Another check would be

  • begin tran
  • load something
  • access a relation to another object from something and access a property (not the pk) of this related object

You might find the last call causes an exception as the session was not kept open from the load because the enclosing txn is not managed by the hibernate txn manager.



来源:https://stackoverflow.com/questions/8122409/is-it-ok-to-use-datasourcetransactionmanager-for-orm-persistence-instead-of-hibe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!