Announcement Announcement Module
No announcement yet.
Custom TransactionDefinition in JpaDialect Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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:

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

    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:

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