Thread: PostgreSQL (XADataSource) as Tomcat Resource
How can I get Postgres to be deployed in Tomcat's JNDI as an XADataSource? I'm running my web app in Tomcat, and I'm moving towards distributed transactions for my two data sources (JDO and JCR). I've got the Jencks library providing JTA support (based on Geronimo's TransactionManager) within Tomcat. Currently, I have Postgres configured as a local web-app Resource as follows: <Resource name="jdbc/whisper_db" auth="Container" type="javax.sql.DataSource" url="jdbc:postgresql://127.0.0.1:5432/my_db" driverClassName="org.postgresql.Driver" username="----------------" password="----------------" maxWait="3000" maxIdle="100" maxActive="10" /> The web-app is able to start up without errors in this case and things function as expected. However, I've been told that I should be using an XADataSource if I want JDO to participate in distributed transactions (specifically, I'm trying to get 2 phase commit). When I change the type to "javax.sql.XADataSource", the web-app fails to start because Tomcat cannot create the JNDI entry. I'm running under Java 1.5, so to my knowledge XADataSource is included. Any pointers would be appreciated. Thanks, Mark
markds75 wrote: > How can I get Postgres to be deployed in Tomcat's JNDI as an > XADataSource? > > I'm running my web app in Tomcat, and I'm moving towards distributed > transactions for my two data sources (JDO and JCR). I've got the > Jencks library providing JTA support (based on Geronimo's > TransactionManager) within Tomcat. Currently, I have Postgres > configured as a local web-app Resource as follows: > > <Resource name="jdbc/whisper_db" > auth="Container" > type="javax.sql.DataSource" > url="jdbc:postgresql://127.0.0.1:5432/my_db" > driverClassName="org.postgresql.Driver" > username="----------------" > password="----------------" > maxWait="3000" > maxIdle="100" > maxActive="10" /> > > The web-app is able to start up without errors in this case and > things function as expected. However, I've been told that I should be > using an XADataSource if I want JDO to participate in distributed > transactions (specifically, I'm trying to get 2 phase commit). When I > change the type to "javax.sql.XADataSource", the web-app fails to > start because Tomcat cannot create the JNDI entry. I'm running under > Java 1.5, so to my knowledge XADataSource is included. What does the Tomcat log tell you when it tried to start up this as an XADatasource? Did it provide any error message? I've not set up an XADatasource in Tomcat, but under JBoss you need to provide additional statements to define an XADatasource. > > Any pointers would be appreciated. > > Thanks, > Mark > > > ---------------------------(end of > broadcast)--------------------------- > TIP 5: don't forget to increase your free space map settings -- Guy Rouillier
The only error is the exception (the Tomcat thrown exception is at the bottom): Caused by: <1|true|4.0.0EA4> kodo.util.InternalException: There was an error when invoking the static getInstance method on the named factory class "class kodo.jdbc.kernel.JDBCBrokerFactory". See the nested exception for details. at kodo.kernel.Bootstrap.getBrokerFactory(Bootstrap.java:96) at kodo.jdo.PersistenceManagerFactoryImpl.getPersistenceManagerFactory(PersistenceManagerFactoryImpl.java:43) ... 61 more Caused by: com.solarmetric.apache.commons.lang.exception.NestableRuntimeException: There was an error duing JNDI lookup of the name "java:comp/env/jdbc/whisper_db". at com.solarmetric.conf.Configurations.lookup(Configurations.java:647) at kodo.conf.KodoConfigurationImpl.lookupConnectionFactory(KodoConfigurationImpl.java:1277) at kodo.conf.KodoConfigurationImpl.getConnectionFactory(KodoConfigurationImpl.java:1259) at kodo.jdbc.conf.JDBCConfigurationImpl.createConnectionFactory(JDBCConfigurationImpl.java:886) at kodo.jdbc.conf.JDBCConfigurationImpl.getDBDictionaryInstance(JDBCConfigurationImpl.java:609) at kodo.jdbc.meta.MappingDefaultsImpl.setConfiguration(MappingDefaultsImpl.java:825) at com.solarmetric.conf.Configurations.configureInstance(Configurations.java:292) at com.solarmetric.conf.Configurations.configureInstance(Configurations.java:243) at com.solarmetric.conf.PluginValue.instantiate(PluginValue.java:115) at com.solarmetric.conf.PluginValue.instantiate(PluginValue.java:105) at kodo.jdbc.conf.JDBCConfigurationImpl.getMappingDefaultsInstance(JDBCConfigurationImpl.java:728) at kodo.jdbc.meta.MappingRepository.<init>(MappingRepository.java:29) at kodo.jdbc.conf.JDBCConfigurationImpl.getMetaDataRepository(JDBCConfigurationImpl.java:749) at kodo.kernel.AbstractBrokerFactory.makeReadOnly(AbstractBrokerFactory.java:683) at kodo.kernel.AbstractBrokerFactory.pool(AbstractBrokerFactory.java:631) at kodo.jdbc.kernel.JDBCBrokerFactory.getInstance(JDBCBrokerFactory.java:53) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at kodo.kernel.Bootstrap.getBrokerFactory(Bootstrap.java:89) ... 62 more Caused by: javax.naming.NamingException: Cannot create resource instance at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:132) at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304) at org.apache.naming.NamingContext.lookup(NamingContext.java:792) at org.apache.naming.NamingContext.lookup(NamingContext.java:139) at org.apache.naming.NamingContext.lookup(NamingContext.java:780) at org.apache.naming.NamingContext.lookup(NamingContext.java:139) at org.apache.naming.NamingContext.lookup(NamingContext.java:780) at org.apache.naming.NamingContext.lookup(NamingContext.java:139) at org.apache.naming.NamingContext.lookup(NamingContext.java:780) at org.apache.naming.NamingContext.lookup(NamingContext.java:152) at org.apache.naming.SelectorContext.lookup(SelectorContext.java:136) at javax.naming.InitialContext.lookup(InitialContext.java:351) at com.solarmetric.conf.Configurations.lookup(Configurations.java:643) ... 82 more
Also, I just noticed that in some examples for other databases, the Resource tag has a "factory" parameter too. Is there an appropriate value (class) for a Postgres connection factory? Mark
markds75 wrote: > The only error is the exception (the Tomcat thrown exception is at the > bottom): > > Caused by: <1|true|4.0.0EA4> kodo.util.InternalException: There was > an error when invoking the static getInstance method on the > named factory class "class > kodo.jdbc.kernel.JDBCBrokerFactory". See the nested exception for > details. at kodo.kernel.Bootstrap.getBrokerFactory(Bootstrap.java:96) > at > kodo.jdo.PersistenceManagerFactoryImpl.getPersistenceManagerFactory(Pers istenceManagerFactoryImpl.java:43) > ... 61 more > Caused by: > com.solarmetric.apache.commons.lang.exception.NestableRuntimeException: > There was an error duing JNDI lookup of the name > "java:comp/env/jdbc/whisper_db". At What is "kodo"? That is not part of the standard Tomcat installation. At any rate, have you read the Tomcat documentation on configuring datasources http://tomcat.apache.org/tomcat-5.5-doc/jndi-datasource-examples-howto.h tml? I did some quick googling on "tomcat XADataSource" and while I got a lot of hits, none of the top 10 seemed to have achieved much success. There are some examples of configuring the factory, so that might come in helpful. I looked in the latest PG JDBC driver jar and I see no support for XA there. Are you certain this is even a supported configuration? -- Guy Rouillier
Kodo is my JDO implementation. It's trying to access the database via JNDI, which succeeds if I use the standard javax.sql.DataSource, but as soon as I make it an XADataSource, I get the error. I used the tomcat page you provided the link for to get things set up to begin with. But since Tomcat itself doesn't have a transaction manager (hence my need to use the Jencks library to get distributed transactions), they don't talk about XADataSource at all, nor do they talk about using a connection factory. I'm using postgresql-8.1-405.jdbc3.jar as my driver. According to the PostgreSQL JDBC FAQ: http://jdbc.postgresql.org/documentation/faq.html XA support started in 8.1dev-403. I checked the classes in the Jar itself, and it includes the org.postgresql.xa package (see http://jdbc.postgresql.org/development/privateapi/index.html for the JavaDocs). The question may be: does the configuration change between using a standard DataSource and an XADataSource? I would think that, at least as far as setting up a JNDI resource, Tomcat wouldn't care if the resource implements DataSource or XADataSource. Most of the search results I found were from before (and mostly years before) XA support was added to the JDBC driver. I was hoping to find someone on this newsgroup with some experience using it... as I understand, its only been 4-6 months since the support was added. Mark
On Wed, 5 Apr 2006, markds75 wrote: > How can I get Postgres to be deployed in Tomcat's JNDI as an > XADataSource? > > I'm running my web app in Tomcat, and I'm moving towards distributed > transactions for my two data sources (JDO and JCR). I've got the Jencks > library providing JTA support (based on Geronimo's TransactionManager) > within Tomcat. Currently, I have Postgres configured as a local web-app > Resource as follows: > > <Resource name="jdbc/whisper_db" > auth="Container" > type="javax.sql.DataSource" > url="jdbc:postgresql://127.0.0.1:5432/my_db" > driverClassName="org.postgresql.Driver" > username="----------------" > password="----------------" > maxWait="3000" > maxIdle="100" > maxActive="10" /> > > The web-app is able to start up without errors in this case and things > function as expected. However, I've been told that I should be using an > XADataSource if I want JDO to participate in distributed transactions > (specifically, I'm trying to get 2 phase commit). When I change the > type to "javax.sql.XADataSource", the web-app fails to start because > Tomcat cannot create the JNDI entry. I'm running under Java 1.5, so to > my knowledge XADataSource is included. > > Any pointers would be appreciated. I don't know how to do it, but you certainly shouldn't have the driver class name (org.postgresql.Driver) there. That's only used for non-XA connections. You should somehow tell it that the class implementing XADataSource is org.postgresql.xa.PGXADataSource. I don't know anything about Jencks, but it seems that it uses the TranQL connector module from Geronimo to glue in XADataSource implementations. Unfortunately, there's no TranQL connector for PostgreSQL. Fortunately, it shouldn't be too hard to write one, using the existing connectors as an example. However, I would suggest using another app server / JTA implementation. I had success with JOnAS, which includes JOTM as it's JTA implementation. JBoss should work too. - Heikki