Thread: PGXADataSource does not implement DataSource
Hello and thanks for for the efforts. I've noticed that your XA implementation does not formally implement javax.sql.DataSource. I felt pretty sure that this was a simple oversight, given that BaseDataSource provides complete compatibility with the DataSource interface. I patched thusly:
Index: org/postgresql/ds/common/BaseDataSource.java
===================================================================
RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/ds/common/BaseDataSource.java,v
retrieving revision 1.7
diff -r1.7 BaseDataSource.java
12a13,14
> import javax.sql.DataSource;
>
25c27
< public abstract class BaseDataSource implements Referenceable
---
> public abstract class BaseDataSource implements Referenceable, DataSource
and now Hibernate happily accepts the postgresql XA using JTA.
Best regards,
Bill Middleton
Index: org/postgresql/ds/common/BaseDataSource.java
===================================================================
RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/ds/common/BaseDataSource.java,v
retrieving revision 1.7
diff -r1.7 BaseDataSource.java
12a13,14
> import javax.sql.DataSource;
>
25c27
< public abstract class BaseDataSource implements Referenceable
---
> public abstract class BaseDataSource implements Referenceable, DataSource
and now Hibernate happily accepts the postgresql XA using JTA.
Best regards,
Bill Middleton
On Fri, 20 Apr 2007, Bill Middleton wrote: > Hello and thanks for for the efforts. I've noticed that your XA > implementation does not formally implement javax.sql.DataSource. I felt > pretty sure that this was a simple oversight, given that BaseDataSource > provides complete compatibility with the DataSource interface. I patched > thusly: > The javadoc doesn't have XADataSource extending Datasource so we didn't either. > and now Hibernate happily accepts the postgresql XA using JTA. > Are you sure this works completely? How is Hiberate able to access any XA things if it's only using a regular Datasource/Connection? Kris Jurka
Bill Middleton wrote: > Hello and thanks for for the efforts. I've noticed that your XA > implementation does not formally implement javax.sql.DataSource. I felt > pretty sure that this was a simple oversight, given that BaseDataSource > provides complete compatibility with the DataSource interface. I patched > thusly: I'm not sure that's a smart a smart thing to do. I don't think there's a requirement for XADataSource implementations to implement DataSource as well. If that was the case, surely XADataSource interface would inherit DataSource to enforce that. If we declare that PGXADataSource implements DataSource, then one can erroneously configure the container to use PGXADataSource in normal DataSource-mode. In fact I suspect that's the case in your environment as well. Can you provide a simple test case involving Hibernate so that I can try this out myself? What's in your hibernate config file? -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com
Hello again, and thanks for the feedback. Yes, I'm likely in way over my head here. However, things are working acceptably with minimal testing so far. I register my modified PGXA as the resource in a UserTransactionService and then pass it into hibernate via jndi lookup, along with a transactionmanager. The interesting bits of hibernate.cfg.xml are then:
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.connection.datasource">java:comp:myDS</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
Hibernate accesses the DS in org.hibernate.connection.DataSourceConnectionProvider
I'm using the atomikos TM, and sharing the DS between hibernate and a (also slightly modified) up jboss cache.
Note that this works fine with Derby's embedded XA datasource, and they do implement DataSource, but again, I'm a novice at all this.
Any further advice appreciated.
<property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="hibernate.connection.datasource">java:comp:myDS</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
Hibernate accesses the DS in org.hibernate.connection.DataSourceConnectionProvider
I'm using the atomikos TM, and sharing the DS between hibernate and a (also slightly modified) up jboss cache.
Note that this works fine with Derby's embedded XA datasource, and they do implement DataSource, but again, I'm a novice at all this.
Any further advice appreciated.
On 4/20/07, Heikki Linnakangas <heikki@enterprisedb.com> wrote:
Bill Middleton wrote:
> Hello and thanks for for the efforts. I've noticed that your XA
> implementation does not formally implement javax.sql.DataSource. I felt
> pretty sure that this was a simple oversight, given that BaseDataSource
> provides complete compatibility with the DataSource interface. I patched
> thusly:
I'm not sure that's a smart a smart thing to do. I don't think there's a
requirement for XADataSource implementations to implement DataSource as
well. If that was the case, surely XADataSource interface would inherit
DataSource to enforce that. If we declare that PGXADataSource implements
DataSource, then one can erroneously configure the container to use
PGXADataSource in normal DataSource-mode. In fact I suspect that's the
case in your environment as well.
Can you provide a simple test case involving Hibernate so that I can try
this out myself? What's in your hibernate config file?
--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com
Bill Middleton wrote: > Hello again, and thanks for the feedback. Yes, I'm likely in way over my > head here. However, things are working acceptably with minimal testing so > far. I register my modified PGXA as the resource in a > UserTransactionService and then pass it into hibernate via jndi lookup, > along with a transactionmanager. The interesting bits of > hibernate.cfg.xmlare then: > > <property name="hibernate.dialect"> > org.hibernate.dialect.PostgreSQLDialect</property> > <property name="hibernate.connection.datasource > ">java:comp:myDS</property> > <property name="hibernate.transaction.factory_class"> > org.hibernate.transaction.JTATransactionFactory</property> > > Hibernate accesses the DS in > org.hibernate.connection.DataSourceConnectionProvider > > I'm using the atomikos TM, and sharing the DS between hibernate and a > (also > slightly modified) up jboss cache. I'm not an expert on hibernate or atomikos, but I don't think hibernate should ever see the raw PGXADataSource object. Whatever is handling the connection pool, either Atomikos or JBoss, should get a connection from the XADataSource object, and wrap that in a DataSource implementation of it's own. That wrapper object is registered in JNDI, and hibernate gets it from there. Where is the connection pool configured? What's in the jboss cache and how is it modified? -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com
I accidentally left the list out of this reply.
---------- Forwarded message ----------
From: Bill Middleton <utvikler@gmail.com >
Date: Apr 21, 2007 12:05 AM
Subject: Re: [JDBC] PGXADataSource does not implement DataSource
To: Heikki Linnakangas <heikki@enterprisedb.com>
Heikki wrote:
Hibernates JTA implementation does use the ordinary usertransaction from atomikos (or jboss, presumably) as bound in jndi, but it seems to require the actual datasource to obtain initial information about the db, and possibly to create table automatically. If I omit it, I get exceptions for not supplying a jdbc connection. And indeed, the XADataSource cast to DataSource is cached in DataSourceConnectionProvider, its getConnection() method is called by several internal classes - but nowhere does it specify an XAConnection or XAResource so....
I guess I'll slink off and test this a bit more, before I conclude that its stable.
Thanks again,
Bill Middleton
---------- Forwarded message ----------
From: Bill Middleton <utvikler@gmail.com >
Date: Apr 21, 2007 12:05 AM
Subject: Re: [JDBC] PGXADataSource does not implement DataSource
To: Heikki Linnakangas <heikki@enterprisedb.com>
Heikki wrote:
I'm not an expert on hibernate or atomikos, but I don't think hibernate
should ever see the raw PGXADataSource object. Whatever is handling the
connection pool, either Atomikos or JBoss, should get a connection from
the XADataSource object, and wrap that in a DataSource implementation of
it's own. That wrapper object is registered in JNDI, and hibernate gets
it from there.
Hibernates JTA implementation does use the ordinary usertransaction from atomikos (or jboss, presumably) as bound in jndi, but it seems to require the actual datasource to obtain initial information about the db, and possibly to create table automatically. If I omit it, I get exceptions for not supplying a jdbc connection. And indeed, the XADataSource cast to DataSource is cached in DataSourceConnectionProvider, its getConnection() method is called by several internal classes - but nowhere does it specify an XAConnection or XAResource so....
I guess I'll slink off and test this a bit more, before I conclude that its stable.
Thanks again,
Bill Middleton