Results 1 to 3 of 3

Thread: Extending JpaTransactionManager with private inner class JpaTransactionObject

  1. #1
    Join Date
    Nov 2012
    Posts
    2

    Default 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. #2
    Join Date
    Apr 2008
    Location
    Seville, Spain
    Posts
    133

    Default

    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
    Jose Luis Martin
    Freelance Senior Consultant
    JDAL - Java Database Application Library

  3. #3
    Join Date
    Nov 2012
    Posts
    2

    Default

    Quote 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...

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •