Announcement Announcement Module
Collapse
No announcement yet.
Extending JpaTransactionManager with private inner class JpaTransactionObject Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Extending JpaTransactionManager with private inner class JpaTransactionObject

    Hello,

    I would like to extend JpaTransactionManager , making it running extra sql in doBegin(), doCommit(), doRollBack() method, but I encounter problems because JpaTransactionObject used in JpaTransactionManager is a private inner class. The extending class cannot see the existence of JpaTransactionObject, thus I cannot get EntityManager in doBegin(), doCommit(), doRollBack().

    Is there any ways extending JpaTransactionManager besides making JpaTransactionObject protected and recompile my own spring-orm.jar?

  • #2
    You can get the EntityManager just after doBegin() with

    Code:
    	EntityManagerHolder emHolder = (EntityManagerHolder)
    				TransactionSynchronizationManager.getResource(getEntityManagerFactory());
    But, as transaction begin, prepare and cleanup is delegated to a JpaDialect strategy, you could extends DefaultJpaDialect (or subclasses) and configure JpaTransactionManger with it.

    Cheers

    Comment


    • #3
      Originally posted by chelu View Post
      You can get the EntityManager just after doBegin() with

      Code:
      	EntityManagerHolder emHolder = (EntityManagerHolder)
      				TransactionSynchronizationManager.getResource(getEntityManagerFactory());
      But, as transaction begin, prepare and cleanup is delegated to a JpaDialect strategy, you could extends DefaultJpaDialect (or subclasses) and configure JpaTransactionManger with it.

      Cheers
      Thank you for the reply. After examing the source code I found that implement this in TransactionManager seems to be a better way, since I cannot get EntityManagerHolder in JpaDialect's cleanupTransaction()

      Another question: Is there any ways of injecting outside data into TransactionManager? My "extra sql" needs some web site information (username logged in and application name for example) to construct the sql string...

      Comment

      Working...
      X