Issue Details (XML | Word | Printable)

Key: OPENJPA-144
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Brad L Vandermoon
Votes: 1
Watchers: 5
Operations

If you were logged in you would be able to see more operations.
OpenJPA

JDBCConfigurationImpl does not support JNDI lookup for non-jta-data-source.

Created: 13/Feb/07 05:25 PM   Updated: 01/Mar/07 02:13 AM
Return to search
Component/s: jdbc
Affects Version/s: None
Fix Version/s: 0.9.7

Time Tracking:
Issue & Sub-Tasks
Issue Only
Not Specified

File Attachments:
  Size
Text File Both-JTAandNonJTASpecified.txt 2007-02-14 09:09 PM Brad L Vandermoon 7 kB
Text File Only-JTASpecified.txt 2007-02-14 09:09 PM Brad L Vandermoon 7 kB
Java Archive File openjpa-144-patch-2.jar 2007-02-15 08:56 PM Patrick Linskey 9 kB
File OPENJPA-144-patch.diff 2007-02-14 11:56 PM Patrick Linskey 3 kB
Java Archive File openjpa-144-patch.jar 2007-02-15 06:22 PM Patrick Linskey 10 kB
Text File PostPatch-144.txt 2007-02-15 08:39 PM Brad L Vandermoon 8 kB
Text File PostPatch-144fix2.txt 2007-02-16 02:50 PM Brad L Vandermoon 8 kB
Environment: WebSphere 6.1, DB2 v8.1 and sequences
Issue Links:
Reference

Resolution Date: 16/Feb/07 04:22 PM

Sub-Tasks  All   Open   
No sub-tasks match this view.

 Description  « Hide
A non-jta-data-source is required for DB2 sequences; however, org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl does not support a JNDI lookup for this data source from the openjpa.ConnectionFactory2Name property as documented (refer to section 5.12 and 4.2.1 of the OpenJPA manual).

It seems like the same implementation for the jta-data-source should be implemented for the non-jta-data-source. i.e.

// ADD createConnectionFactory2()
private DecoratingDataSource createConnectionFactory2() {
        DataSource ds = (DataSource) connectionFactory2.get();
        if (ds != null)
            return setupConnectionFactory(ds, true);

        ds = (DataSource) super.getConnectionFactory2(); // JNDI lookup
        if (ds == null)
            ds = DataSourceFactory.newDataSource(this, true);

        return setupConnectionFactory(ds, true);
    }

// MODIFY this method
public Object getConnectionFactory2() {
        // override to configure data source
        if (dataSource2 == null) {
            DecoratingDataSource ds = createConnectionFactory2();
            dataSource2 = DataSourceFactory.installDBDictionary
                (getDBDictionaryInstance(), ds, this, true);
        }
        return dataSource2;
    }



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Patrick Linskey added a comment - 13/Feb/07 05:38 PM
Are you also specifying a jta-data-source, or only a non-jta-data-source? If specifying both, what error do you get when you don't specify a non-jta-data-source at all? I believe that there could be a problem, but I did some work a while back that makes it unnecessary to specify a non-jta-data-source if you're specifying a jta-data-source. That code works on WebLogic, but that's the only environment that I've tested it in.

Brad L Vandermoon added a comment - 14/Feb/07 12:57 PM
The above solution is offered as an analysis level solution only. Testing is in process.

Brad L Vandermoon added a comment - 14/Feb/07 01:18 PM
When we specify only a jta-data-source, we get: "<4|false|0.9.7-incubating-SNAPSHOT> org.apache.openjpa.util.InvalidStateException: Unable to execute suspend on a WebSphere managed transaction. WebSphere does not support direct manipulation of managed transactions."

When we try to use JNDI to specify the non-jta-data-source, we get the same error. JDBCConfigurationImpl doesn't appear to use this information to populate datasource2.

When we pass the properties to have OpenJPA create the connection it works fine. Here's the properties we pass:

       <entry key="openjpa.Connection2DriverName" value="com.ibm.db2.jcc.DB2Driver"/>
        <entry key="openjpa.Connection2UserName" value="Test"/>
        <entry key="openjpa.Connection2Password" value="password"/>
        <entry key="openjpa.Connection2URL" value="jdbc:db2://localhost:3700/RQSTSET"/>
        <entry key="openjpa.jdbc.Schema" value="PROPCAS"/>

In this later case, JDBCConfigurationImpl creates a SimpleDriverDataSource for the datasource2 and uses it to do the sequence.

Patrick Linskey added a comment - 14/Feb/07 05:02 PM
Interesting. Can you post the full stack trace both without specifying a non-jta-data-source and with a non-jta-data-source specified?

Brad L Vandermoon added a comment - 14/Feb/07 09:09 PM
Requested stack traces provided above. I also verified that JDBCConfigurationImpl.connectionFactory2Name contained my non-jta-data-source reference (i.e. "java:comp/env/jdbc/RequestSetNoTran") when producing Both-JTAandNonJTASpecified.txt.

Patrick Linskey added a comment - 14/Feb/07 09:37 PM
It looks like there are two issues here. First, we seem to be incorrectly attempting to suspend the transaction when a non-jta data source is specified. Second, our WAS integration does not allow suspending of the JTA transaction. I will create a new issue for this second problem.

Brad L Vandermoon added a comment - 14/Feb/07 09:51 PM
Great. Is there something I can do?

Patrick Linskey added a comment - 14/Feb/07 10:01 PM
If you could create and attach a patch akin to what you described in the original notes, that'd be great. One modification: instead of adding a new createConnectionFactory2() method, it'd be great if you could just modify the (private) createConnectionFactory() method that exists already, maybe to take as an argument a boolean indicating which connection factory to use.

Patrick Linskey added a comment - 14/Feb/07 11:56 PM
It turns out I had a few free minutes. Attached is a wholly-untested patch to JDBCConfigurationImpl.java that might work. Can you test this out and let me know if it works?

If you don't have access to the OpenJPA sources, I can build a jar with the patched class in it for testing also.

Brad L Vandermoon added a comment - 15/Feb/07 12:52 PM
I will test today.

Brad L Vandermoon added a comment - 15/Feb/07 02:00 PM
I thought I could get this from the svn repository, but it does not appear as though the java file has been checked in. If you'd attach the java file, I can test.

Bottom line I only have access to the subversion web interface.

Patrick Linskey added a comment - 15/Feb/07 06:21 PM
I've attached a jar file containing the compiled class. Put this jar ahead of OpenJPA in your classpath.

FTR, the source for the file in question is at https://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/conf/JDBCConfigurationImpl.java

Brad L Vandermoon added a comment - 15/Feb/07 08:39 PM
The error has changed a bit. New stack trace is in PostPatch-144. Debugging indicates that JDCConfigurationImpl.datasource2 contains a managed datasource.

Patrick Linskey added a comment - 15/Feb/07 08:56 PM
Oops, I made a mistake in the createConnectionFactory() logic. This one looks better.

Brad L Vandermoon added a comment - 15/Feb/07 11:05 PM
I am getting a different error this time, but before I pass on the stack trace information, perhaps you can tell me what properties you'd expect to see set i.e. non-jta-data-source, openjpa.Connection2DriverName, openjpa.ConnectionFactory2Name, etc.....

Patrick Linskey added a comment - 15/Feb/07 11:17 PM
For openjpa-144-patch-2.jar, I would expect you to need to set jta-data-source and non-jta-data-source appropriately. The second patch should correctly pick up the non-jta-data-source and use it for sequence purposes.

Brad L Vandermoon added a comment - 16/Feb/07 02:50 PM
Getting a different exception now. It is contained in attached "PostPatch-144fix2.txt". It appears as though all JNDI lookups in WebSphere return a managed connection as JDBCConfigurationImpl.datasource2 contains an instance of com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource.

Just to recap. Without the patches, I have been able to get sequences two work by two different methods:

Approach 1: specify connection properties so OpenJPA can build a SimpleDriverDataSource. Properties are as follows:

        <entry key="openjpa.Connection2DriverName" value="com.ibm.db2.jcc.DB2Driver"/>
        <entry key="openjpa.Connection2UserName" value="Test"/>
        <entry key="openjpa.Connection2Password" value="xxxxxxxx"/>
        <entry key="openjpa.Connection2URL" value="jdbc:db2://localhost:3700/RQSTSET"/>
        <entry key="openjpa.jdbc.Schema" value="PROPCAS"/>

       Under this approach, SimpleDriverDataSource is contained in JDBCConfigurationImpl.datasource2.

Approach 2: pass the webspeher transaction manager to OpenJPA per the below property:

        <entry key="openjpa.ManagedRuntime" value="invocation(TransactionManagerMethod=com.ibm.ws.Transaction.TransactionManagerFactory.getTransactionManager)"/>



Patrick Linskey added a comment - 16/Feb/07 04:22 PM
I'm guessing that Approach 2 works with just a single jta-data-source listed, right?

Also, your description implies that with the most recent code, OpenJPA is looking up the non-jta-data-source, but WAS is still returning a data source with limitations. Is that correct? Based on this assumption, I will close this issue and create a new one re: our defaults and corresponding WAS limitations.

Brad L Vandermoon added a comment - 16/Feb/07 08:00 PM
Approach 2 will actually work when specifying only the jta-data-source or specifying both the jta-data-source and the non-jta-data-source.

As far as your second question: WAS is retuning a managed connection for the second data source.