Announcement Announcement Module
Collapse
No announcement yet.
EJB CMT Propogation issue Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • EJB CMT Propogation issue

    I have a stateless session EJB that uses one DAO (that extends JDBCDaoSupport). This DAO in turn, uses two StoredProcedure classes. Since the EJB method is under transaction (described as *Required* in ejb-jar.xml) I, was expecting Spring classes to somehow be aware of it and therefore use the same connection in the StoredProcedure classes. However, this is not happening. (Since I can only pass DataSource as a parameter to the StoredProcedure classes, I have no control on which connection they will get themseleves from it). When I look in the debugger, both StoredProcedure classes have different instances of Connection object. I used the following code in the DAO to check the connection instance in each storedprocedure class.

    Connection con = DataSourceUtils.getConnection(summarySPAO.getJdbcT emplate().getDataSource());
    Connection con = DataSourceUtils.getConnection(callerSPAO.getJdbcTe mplate().getDataSource());

    If the classes are under CMT, they should have the same connection but they did not. Is there something I need to do to make them do that ? I am trying to read more on the Spring transaction handling. In the meantime, I am going to use a singleConnectionDataSource in the DAO and pass it to both the StoredProcedure classes. That way I am guranteed to have same connection in both. And that works, however, this is not the way I want to structure the code. I was hoping for Spring to handle the transactions properly because the documentation clearly says so. If someone has encountered this or have suggestions, please help.

    Thanks,


    --BonBon

  • #2
    Is the datasource looked up from the container using JNDI, the exact same datasource used by the bean for non-Spring getConnection calls and is it configured to participate as part of a JTA transaction?

    Since you are using CMT, using DataSourceUtils won't affect anything (although its still a good practice in case you switch to BMT and use Spring's transaction manager). At this point you are relying on the container's datasources to properly participate in a CMT JTA transaction.

    Comment


    • #3
      Is the datasource looked up from the container using JNDI, the exact same datasource used by the bean for non-Spring getConnection calls and is it configured to participate as part of a JTA transaction?

      BonBon: Yes. The Container is Weblogic 8.1 and I look up the datasource through JNDI and it is configured to handle transactions.

      Since you are using CMT, using DataSourceUtils won't affect anything (although its still a good practice in case you switch to BMT and use Spring's transaction manager). At this point you are relying on the container's datasources to properly participate in a CMT JTA transaction.

      BonBon: I guess, my post above is not very clear. I use this method :
      Connection con = DataSourceUtils.getConnection(summarySPAO.getJdbcT emplate().getDataSource());

      just to see the connection object in the debugger so that I can compare the two. I don't actually do anything with the Connection Object. I was just trying to see if the two objects are the same, that's all.

      Looks like what you are saying is that I should look into Weblogic Datasource configuration, etc. (although there is not much there) instead of SPRING. But the EJBs work fine otherwise.

      Thanks,

      --Bon Bon

      Comment


      • #4
        Originally posted by canbonbon View Post
        Looks like what you are saying is that I should look into Weblogic Datasource configuration, etc. (although there is not much there) instead of SPRING. But the EJBs work fine otherwise.
        Yes, that is what I'm saying.

        Are you using an XA compatible driver?

        Have you turned on more logging on the weblogic server? I its debug logging might be able to show what is going on.

        We use BMT for our code. That allows you to use the full Spring transaction API. But for your simple example CMT should work fine.

        Comment


        • #5
          Originally posted by canbonbon View Post
          I have a stateless session EJB that uses one DAO (that extends JDBCDaoSupport). This DAO in turn, uses two StoredProcedure classes. Since the EJB method is under transaction (described as *Required* in ejb-jar.xml) I, was expecting Spring classes to somehow be aware of it and therefore use the same connection in the StoredProcedure classes. However, this is not happening.
          ...
          If the classes are under CMT, they should have the same connection but they did not. Is there something I need to do to make them do that ?
          Hi,

          you need to give us some more info: the contents of your applicationContext would really help. Are you using Spring's JtaTransactionManager? If not, you should, since that's the only way to participate in the CMT. Also, does your EJB have a reference to your DataSource?

          Joris

          Comment

          Working...
          X