1 2 Previous Next 18 Replies Latest reply on Apr 11, 2007 3:03 PM by asavitsky

    Tomcat deployment with external datasource - is it possible?

      I'm currently trying to adopt the Seam JPA example to our Tomcat deployment guidelines, and I'm facing a problem here...

      The example uses a DataSource that is supplied by the Microcontainer, in jboss-beans.xml:

      <bean name="bookingDatasourceFactory"
       class="org.jboss.seam.microcontainer.DataSourceFactory">
       <property name="driverClass">org.hsqldb.jdbcDriver</property>
       <property name="connectionUrl">jdbc:hsqldb:.</property>
       <property name="userName">sa</property>
       <property name="jndiName">java:/DefaultDS</property>
       <property name="minSize">0</property>
       <property name="maxSize">10</property>
       <property name="blockingTimeout">1000</property>
       <property name="idleTimeout">100000</property>
       <property name="transactionManager">
       <inject bean="TransactionManager" />
       </property>
       </bean>
       <bean name="bookingDatasource" class="java.lang.Object">
       <constructor factoryMethod="getDataSource">
       <factory bean="bookingDatasourceFactory" />
       </constructor>
       </bean>
      


      My question is: is it possible to somehow use the DataSource that is configured in Tomcat, as in

      <?xml version="1.0" encoding="UTF-8"?>
      <Context>
       <Resource name="jdbc/DataSource" auth="Container"
       type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="username" password="password" driverClassName="oracle.jdbc.driver.OracleDriver" url="jdbc url" />
      </Context>
      


      The idea is to be able to create data sources outside the deployed WAR, so that the same WAR could be deployed to different environments without any changes - this is a common requirement for production-level Tomcat applications.

      When I try to remove the data source definition from jboss-beans.xml, it gives me the "name not bound" exception (naturally), and I suspect that it only uses the Microcontainer's JNDI, ignoring the Tomcat-supplied one.

      Is such setup supported at all? Is there any way to configure the data source outside the WAR, while using Seam/Microcontainer/JPA stack?

      Thanks,

      Alex

        • 1. Re: Tomcat deployment with external datasource - is it possi

          What did you use as the JNDI name in persistence.xml?

          • 2. Re: Tomcat deployment with external datasource - is it possi
            baz

            Yes it is possible, but AFAIK you are losing seam managed transactions.
            The last time i was using this was in March 2006. Until then i am bound to seam managed transactions.
            But if i am wrong, and external datasources in combination with seam managed transactions in tomcat are possible, please tell me how.
            But nevertheless, new projects will be deployed to an application server.
            Ciao,


            • 3. Re: Tomcat deployment with external datasource - is it possi

              Norman,

              Here's my persistence.xml file:

              <?xml version="1.0" encoding="UTF-8"?>
              <persistence xmlns="http://java.sun.com/xml/ns/persistence"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
               version="1.0">
               <persistence-unit name="visitsDatabase" transaction-type="JTA">
               <provider>org.hibernate.ejb.HibernatePersistence</provider>
               <jta-data-source>java:comp/env/jdbc/DataSource</jta-data-source>
               <properties>
               <property name="hibernate.show_sql" value="true" />
               <property name="hibernate.cache.provider_class"
               value="org.hibernate.cache.HashtableCacheProvider" />
               <property name="hibernate.transaction.manager_lookup_class"
               value="org.hibernate.transaction.JBossTransactionManagerLookup" />
               <property name="hibernate.bytecode.provider" value="javassist" />
               <property name="hibernate.jdbc.batch_size" value="0" />
               </properties>
               </persistence-unit>
              </persistence>
              


              Actually, I have tried several ways of referencing the Tomcat JNDI data source, like: "jdbc/DataSource", "java:/jdbc/DataSource", "java:comp/env/jdbc/DataSource", "java:/DataSource". The JNDI name defined in Tomcat is "jdbc/DataSource"

              Thanks,

              Alex

              • 4. Re: Tomcat deployment with external datasource - is it possi

                Baz, could you please post your setup that you said was working? And what do you mean by "losing Seam-managed transactions"? Did you still use Seam's transactional JSF interceptor?

                Overall, I'm leaning towards opening a JIRA issue for that, as it doesn't look like it's possible to mix the lookups to the Microcontainer JNDI and to the Tomcat one...

                • 5. Re: Tomcat deployment with external datasource - is it possi

                  It wouldn't surprise me at all if the microcontainer overrides tomcat's JNDI. My understanding is that tomcat JNDI is read-only and is too limited for any sort of serious extension.

                  Honestly, if you need appserver class deployment options that you consider using an appserver.

                  • 6. Re: Tomcat deployment with external datasource - is it possi
                    baz

                    Hello,
                    i do not have the setup anymore:-(
                    But when i was using 'tomcats' datasource i wasn't using the microcontainer.
                    And Normans statement makes sense to me.
                    From chapter 21.5 of the seam docs:


                    The Seam support for Hibernate and JPA requires JTA and a JCA datasource. If you are running
                    in a non-EE environment like Tomcat or TestNG you can run these services, and Hibernate itself,
                    in the JBoss Microcontainer.

                    And for this setup, with microcontainer, i have never managed to access the tomcat resources.
                    So for conclusion, all of our new projects will be deployed to an appserver.
                    Ciao,
                    Carsten

                    • 7. Re: Tomcat deployment with external datasource - is it possi

                       

                      "baz" wrote:
                      Hello,
                      i do not have the setup anymore:-(
                      But when i was using 'tomcats' datasource i wasn't using the microcontainer.


                      You mean - you were simply using a JTA-compliant TM, like I ended up doing? I finally sacked the MC and installed JOTM instead, and it works, with Tomcat datasource and such :) Is this what you've meant when you said you couldn't use the Seam-managed transactions with such setup? I haven't checked yet whether they work in my setup or not, gonna do it first thing today...


                      • 8. Re: Tomcat deployment with external datasource - is it possi
                        baz

                        I have never tried to use JOTM. But two years ago i considered using it.
                        But switched to the microcontainer setup.

                        • 9. Re: Tomcat deployment with external datasource - is it possi

                          Actually, any JTA-compliant TM should do, I suppose, JOTM was picked only because it was the first one I've heard about (I plan to try Atomikos, and to ask around who's using what on Spring forum). No MC for me for sure, as any appservers are off-limits in our environment, and the ability to use Tomcat DS is a must.

                          Now, sorry for being persistent, but could you expand a little bit more on why you couldn't use Seam-managed Tx in your setup?

                          Thanks,

                          Alex

                          • 10. Re: Tomcat deployment with external datasource - is it possi
                            baz

                            I will repeat the parts that i have written

                            but AFAIK you are losing seam managed transactions.


                            But if i am wrong, and external datasources in combination with seam managed transactions in tomcat are possible, please tell me how.

                            Conclusion: i am not sure but i have no time to test the opposite

                            • 11. Re: Tomcat deployment with external datasource - is it possi
                              youngm

                              I've created a jira issue and a candidate patch for pluggable transaction management in seam. This will allow for use of seam without a dependence on JTA obtained through JNDI. If you want try out the patch and post any feedback you have. At the very least if this is a feature you are interested in vote for it.

                              Thanks,
                              Mike

                              • 12. Re: Tomcat deployment with external datasource - is it possi

                                Improvement created by Michael:
                                http://jira.jboss.org/jira/browse/JBSEAM-1144

                                Great idea, +1 for me. Support, please.

                                • 13. Re: Tomcat deployment with external datasource - is it possi

                                  Great work, Mike! This one gets +1 from me as well.

                                  BTW, in the meantime I managed to configure Seam (with managed transactions, PCs and the like) without the microcontainer at all - using either JOTM, Atomikos, or JBoss Transactions. Actually, the latter, being a JBoss product, might even be suitable to be included as a Seam-Tomcat example (instead of Microcontainer)

                                  • 14. Re: Tomcat deployment with external datasource - is it possi
                                    youngm

                                     

                                    BTW, in the meantime I managed to configure Seam (with managed transactions, PCs and the like) without the microcontainer at all - using either JOTM, Atomikos, or JBoss Transactions.


                                    It would be great if you could post how you did that in the Seam WIKI or something for others to see since things aren't looking so good for JBSEAM-1144. :)

                                    Mike

                                    1 2 Previous Next