Announcement Announcement Module
Collapse
No announcement yet.
Custom TransactionDefinition in JpaDialect Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Custom TransactionDefinition in JpaDialect

    Hi all,
    I have a web application configured with Spring 3.0 + JPA. The services are annotated for transactions using a custom annotation. For example, a transactional method could be annotated as following:

    Code:
    @MyCustomTransactionalAnnotation(value=true)
    @Transactional
    public void myServiceMethod() {
        // ...
    }
    As explained here, I configured my own annotation parser which is used to get extra information about the transactionality (the @MyCustomTransactionalAnnotation above).

    Eventually (when a transaction is needed) Spring's JpaTransactionManager will call my own JpaDialect, passing both the EntityManger and the TransactionDefinition (derived from the result returned by my custom annotation parser).

    Code:
    Object beginTransaction(EntityManager entityManager, TransactionDefinition definition)
    			throws PersistenceException, SQLException, TransactionException;
    My JpaDialect receives a TransactionDefinition object which does not expose the information my custom parser provides. The exact hiearchy of the passed definition (in Spring 3.1) is:

    Code:
    org.springframework.transaction.TransactionDefinition
        +org.springframework.transaction.interceptor.DelegatingTransactionAttribute
            +my custom TransactionAnnotationParser
    In practice, my JpaDialect does not have access to the extra transactional information added from my parser. This because the default JpaTransactionManager hides the transaction attributes in an anonymous class.

    How could my JpaDialect get the extra information obtained by my annotation parser?

    I currently user reflection in order to access private internal fields, but this is far away from being nice design...
Working...
X