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

后端 未结 1 796
南笙
南笙 2021-02-06 03:49

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

相关标签:
1条回答
  • 2021-02-06 04:37

    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.

    0 讨论(0)
提交回复
热议问题