Announcement Announcement Module
No announcement yet.
SI and JPA transactions Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • SI and JPA transactions

    We have the following problem.

    the pipeline is simple:

    we hit the gateway and pass our Roo generated objects.
    We then pass the Roo object as the payload.
    Transformer is able to access lazy loaded collections on the payload, find some other roo managed objects update them, persist/merge them.
    Everything is fine.

    However, this is not the case with SA.
    It throws LazyLoading exception after the first Roo finder, we execute in SA.

    When i turn on the spring orm jpa logging, things became more clear.

    This is the trace when message reaches SA:
    11:05:56,750 DEBUG MyServiceActivator.execute(23) | started service activator 
    11:05:56,752 DEBUG SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(231) | Creating new EntityManager for shared EntityManager invocation
    11:05:56,759 DEBUG EntityManagerFactoryUtils.closeEntityManager(328) | Closing JPA EntityManager
    11:05:56,763  ERROR LazyInitializationException.<init>(42) | failed to lazily initialize a collection of role: com.acme.core.model.config.MyConfig.tasks, no session or session was closed
    org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.acme.core.model.config.MyConfig.tasks, no session or session was closed
    Interesting thing is that it looks like previuosly executed transformer had different transaction and entity manager!?

    11:05:55,998  DEBUG JpaTransactionManager.processCommit(752) | Initiating transaction commit
    11:05:55,998  DEBUG JpaTransactionManager.doCommit(462) | Committing JPA transaction on EntityManager [[email protected]]
    11:05:56,000 DEBUG JpaTransactionManager.doCleanupAfterCompletion(548) | Closing JPA EntityManager [[email protected]] after transaction
    11:05:56,000 DEBUG EntityManagerFactoryUtils.closeEntityManager(328) | Closing JPA EntityManager
    Why? I have direct channel, between all the components.
    I execute transformer and splitter in chain, and SA outside the chain.
    Adding SA in chain didn't help.

    My understanding after reading Transaction boundaries chapter in spring ref guide, is that I should have the same transaction context in piepline if I have direct channels between message handlers, which I do.

    How I eventually solved the issue:
    I put @Transactional annotation on my SA and surprisingly everything works, no LazyLoading problem. Looks like TransactionManager is also different (now it is JPA)...

    09:26:19,870  JpaTransactionManager.getTransaction(365) | Creating new transaction with name [com.acme.MyServiceActivator.execute]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT; ''
    09:26:19,871 DEBUG JpaTransactionManager.doBegin(323) | Opened new EntityManager [[email protected]] for JPA transaction

    I think I don't understand things here deep enough.
    Why is this happening?

    Thanks a lot for any hint or explanation.
    Last edited by clandestino_bgd; Apr 16th, 2011, 05:51 AM.

  • #2
    Could you do one last thing. Instead of putting @Transactional on SA put it on the Gateway method.


    • #3
      Hi Oleg,
      Tried that before, didn't help.

      btw, googled this:

      Is this somehow related?



      • #4



        • #5
          Can you describe and/or show logs for the behavior after moving the @Transactional annotation to the gateway method? The reason that was suggested is that it would widen the scope of your transaction to encompass everything that happens downstream from that gateway. Otherwise, your transaction boundaries only wrap the individual transformer and service-activator methods (hence the narrower, distinct transactions).