Announcement Announcement Module
Collapse
No announcement yet.
init-method comes before @Transactional Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • init-method comes before @Transactional

    Hey there, I have a class with a public @Transactional method which loads some values from the DB.

    I'm declaring the bean in the xml with the init-method argument set.

    The problem I'm facing is that it seams that the init-method gets called before the bean is proxified because of the @Transactional. So it's failing because Hibernate's losing the connection.

    Is this correct ? I thought that init-method was called after "everything" was ready. Including the proxy.

    If so, how do I change the order so that init-method calls the proxified bean and not the vainilla implementation?

    PS: yes, Spring AOP is configured correctly and it works OK if I call the init-method from outside (after the bean has been created completely) and not from the bean declaration itself.

    Thank you!

    Fede.

  • #2
    Is this correct ? I thought that init-method was called after "everything" was ready. Including the proxy.
    You are wrong... the init method is called after construction and after all the properties have been set.. So BEFORE the proxies are created. If you want to make it transactional you will have to do it yourself by using for instance a TransactionTemplate inside your method... If all you want is to setup some data create an ApplicationListener which listens for ContectRefreshed events and when received initialize your data...

    BTW this question has been answered numerous times before so I also suggest the search....

    Comment


    • #3
      FYI, the best answer I've found to this is here:
      http://forum.springsource.org/showth...167#post138167
      Just put your transactional logic in a service, and call it from your init method.

      Comment

      Working...
      X