2 Replies Latest reply on Nov 14, 2007 3:50 PM by Magnus Poromaa

    JBoss DataSource  /Transaction Manager and Spring

    Magnus Poromaa Newbie

      Hi

      I don't know if this is the place to make this question but I'll try.

      So I have an application using Spring + JBoss. Since I just recently integrated the spring security framework (meaning acegi) I use a JdbcTemplate, which has a DataSource that it uses to get the connection. At the same time I user the Hibernate SessionFactory, which also use the same data source to fetch connections.

      So the problem I have is that I want to get the same connection which should be handled by the TransactionManager and then be under the same transaction.

      How is the transaction working ? I kind of figured out that the datasource returns ManagedConnections where I guess the close method is overridden to avoid having a close called on the underlaying connection, which is pooled. What happens if I call a close method? Is JBoss keeping track of if the user is doing this and then letting the ManagedConnectionInterceptor warn the user that "hey you did not close the connection I will do it but next time please close it your self". If this is the case what happens if I remove the ManagedConnectionInterceptor will the underlaying connection be keept open and thereby work when the next call comes in.

      The reason I'm asking is that the JdbcTemplate per defult closes the connection and if I override that what will happen?

      On that note what happens if I let the JdbcTemplate close the connection, which is a ManagedConnection wil that close the underlaying connection ?


      How is the TransactionManager involed in all this. I guess it starts a transaction and keeps it in a thread local (or something simular) and then it enlists all the transaction enabled resources I use and do a two-phase commit when the transaction manager is asked to end te transaction? I'm a bit vague here since I really dot now how it works and maybe some kind soul feel like explaining it to another soul :-) Especialy how is the transaction manager working togheter with the Hibernate SessionFactory so hat the DataSource nows to return a ManagedConnection that is tied to the TransactionManager...?


      The real problem is that I want to combine the transaction interceptor in Spring with the Hibernate SessionFactory and a JdbcTemplate using the same DataSource.


      Hope its not to much at one time but I just frustrated about my limited mind not getting it all 100 %


      Cheers
      Magnus