6 Replies Latest reply on Jan 2, 2007 6:32 PM by Norman Richards

    JDBC Transaction integration

    Francisco Lozano Newbie

      Hello,

      I'm new to Seam and I'm evaluating JBoss Seam as our next development platform, replacing our chaotic ASP.NET + Spring.NET + NHibernate.

      Currently we're happy with doing most of our interactions with the database "ORM"-based, this approach saves time and increases portability and it's arguably more "object-oriented".

      But there are a few processes that *must* be done in SQL, in pure JDBC calls. In Spring it's easy to join JDBC and ORM transactions, but I don't know how can achieve this in Seam.

      We'll be using SQL Server 2005, which provides a (hopefully) working XADataSource implementation. We also want to use JMS (as a replacement for the crappy MSMQ ), so we'd like to join also these kind of transactions with the PersistenceManager and the pure JDBC ones.

      Can I "inject" a DataSource in any Seam-managed bean? or I have to look-up it with JDNI?

      Given a DataSource, how can I "join" it with the other (JMS and javax.persistence) transactions?

      I guess it's not Seam but JBoss AS the one that does all this, as it's the JTA implementor, but how can I do it with Seam? I'm quite lost... maybe my java knowledge is too much biased to Spring-based solutions, but I *want* to move to Seam as its conversation and jBPM features are exactly what we need... So any help on this would be welcome.

        • 1. Re: JDBC Transaction integration
          Hung Tang Apprentice

          JPA supports native named queries using @NamedNativeQuery annotation. You can use JDBC with this approach.

          • 2. Re: JDBC Transaction integration
            Francisco Lozano Newbie

             

            "hstang" wrote:
            JPA supports native named queries using @NamedNativeQuery annotation. You can use JDBC with this approach.



            It's an interesting approach, but what about the JMS transactions?

            • 3. Re: JDBC Transaction integration
              Hung Tang Apprentice

              Good question.

              I am unsure if Seam provides a transactional session, but I wouldn't think it's too hard to do.

              Perhaps someone else more knowledgeable on this topic(no pun intended) can comment on this

              • 4. Re: JDBC Transaction integration
                Norman Richards Master

                Yes, you'll find that JPA let's you do pretty much what you want. If not, you can hit the datasource. You can't inject a datasource directly. You'd need to create an @Unwrap component to perform the actual datasource JNDI lookup. Then you can directly inject it. Or, you can use an EJB3 component and use the @Resource annotation to get the data source. But, I'd recommend trying to use the JPA functionality.

                Datasources are transactional and are aware of your JTA transaction. You don't have to do ANYTHING to get this to work. I would recommend using the TransactionalSeamPhaseListener and letting Seam manage the transactions to let Seam control the transaction boundaries.

                If all of your stuff is going to the same DB, I don't think you truly need XA. But, if you do, have a look at the new jboss transaction manager. http://labs.jboss.com/portal/jbosstm. (the old arjuna stuff)

                • 5. Re: JDBC Transaction integration
                  Francisco Lozano Newbie

                   

                  "norman.richards@jboss.com" wrote:
                  Yes, you'll find that JPA let's you do pretty much what you want. If not, you can hit the datasource. You can't inject a datasource directly. You'd need to create an @Unwrap component to perform the actual datasource JNDI lookup. Then you can directly inject it. Or, you can use an EJB3 component and use the @Resource annotation to get the data source. But, I'd recommend trying to use the JPA functionality.

                  Datasources are transactional and are aware of your JTA transaction. You don't have to do ANYTHING to get this to work. I would recommend using the TransactionalSeamPhaseListener and letting Seam manage the transactions to let Seam control the transaction boundaries.

                  If all of your stuff is going to the same DB, I don't think you truly need XA. But, if you do, have a look at the new jboss transaction manager. http://labs.jboss.com/portal/jbosstm. (the old arjuna stuff)


                  Thankyou very much for such a deep answer, it's very helpful. I'll check all these topics shortly :)

                  Our transactions are all against the same database (if using the same datasource in JPA and in pure JDBC, I don't think we'll have any problem, right?). The only problem is JMS, but I guess it's also covered by what you said and by marking a given method @Transactional, all the JMS operations performed within the boundaries of that method become part of the same transaction.

                  • 6. Re: JDBC Transaction integration
                    Norman Richards Master

                    If everything is using the same datasource, you shouldn't have any special TX concerns. With a Seam-managed tx, seam will start the tx at the right time so that everything comes together right and you won't have to worry about @Transactional or anything like that, at least not in the general case.