You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@geronimo.apache.org by Neal Sanche <ne...@nsdev.org> on 2005/06/18 06:30:38 UTC
Application Scoped JDBC Connector for CMP
Hi All,
I'm currently having trouble with a CMP bean getting access to a MySql
database when the deployment plans for the JDBC Connector are
application scoped. Here's what I've done, can you see something wrong
with what I'm doing?
application.xml
<application
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/application_1_4.xsd"
version="1.4">
<module>
<ejb>phonebook-ejb.jar</ejb>
</module>
<module>
<web>
<web-uri>phonebook.war</web-uri>
<context-root>/phonebook</context-root>
</web>
</module>
<module>
<connector>tranql-connector-1.0-SNAPSHOT.rar</connector>
</module>
</application>
geronimo-application.xml
<application
xmlns="http://geronimo.apache.org/xml/ns/j2ee/application"
configId="org/acme/PhoneBook">
<module>
<connector>tranql-connector-1.0-SNAPSHOT.rar</connector>
<alt-dd>mysql-plan.xml</alt-dd>
</module>
</application>
mysql-plan.xml
<connector xmlns="http://geronimo.apache.org/xml/ns/j2ee/connector"
version="1.5" configId="MysqlDatabase"
parentId="org/apache/geronimo/Server">
<dependency>
<uri>mysql/jars/mysql-connector-java-3.1.8-bin.jar</uri>
</dependency>
<resourceadapter>
<outbound-resourceadapter>
<connection-definition>
<connectionfactory-interface> javax.sql.DataSource
</connectionfactory-interface>
<connectiondefinition-instance>
<name>MysqlDataSource</name>
<config-property-setting name="UserName"> geronimo
</config-property-setting>
<config-property-setting name="Password"> geronimo
</config-property-setting>
<config-property-setting name="Driver">
com.mysql.jdbc.Driver </config-property-setting>
<config-property-setting name="ConnectionURL">
jdbc:mysql://localhost/geronimo </config-property-setting>
<config-property-setting
name="CommitBeforeAutocommit"> false </config-property-setting>
<config-property-setting
name="ExceptionSorterClass">
org.tranql.connector.NoExceptionsAreFatalSorter </config-property-setting>
<connectionmanager>
<local-transaction/>
<single-pool>
<max-size>10</max-size>
<min-size>0</min-size>
<blocking-timeout-milliseconds> 5000
</blocking-timeout-milliseconds>
<idle-timeout-minutes>30</idle-timeout-minutes>
<match-one/>
</single-pool>
</connectionmanager>
<global-jndi-name> jdbc/MysqlDatabase
</global-jndi-name>
</connectiondefinition-instance>
</connection-definition>
</outbound-resourceadapter>
</resourceadapter>
</connector>
openejb-jar.xml
<openejb-jar
xmlns="http://www.openejb.org/xml/ns/openejb-jar"
configId="org/acme/PhonebookEJB"
parentId="MysqlDatabase">
<cmp-connection-factory>
<application>org/acme/PhoneBook</application>
<module>MysqlDatabase</module>
<name>MysqlDataSource</name>
</cmp-connection-factory>
<enterprise-beans>
<entity>
<ejb-name>PhoneBookEntry</ejb-name>
<jndi-name>PhoneBookEntry</jndi-name>
<local-jndi-name>java:comp/env/ejb/PhoneBookEntryLocal</local-jndi-name>
<table-name>phone</table-name>
<cmp-field-mapping>
<cmp-field-name>name</cmp-field-name>
<table-column>name</table-column>
</cmp-field-mapping>
<cmp-field-mapping>
<cmp-field-name>phoneNumber</cmp-field-name>
<table-column>phone</table-column>
</cmp-field-mapping>
<resource-ref>
<ref-name>jdbc/basic/entityDatabase</ref-name>
<application>null</application>
<module>MysqlDatabase</module>
<name>PhonebookDBPool</name>
</resource-ref>
</entity>
<session>
<ejb-name>PhoneBookSession</ejb-name>
<jndi-name>org.acme.phonebook.ejb/PhoneBookSession/Home</jndi-name>
<local-jndi-name>java:comp/env/ejb/PhoneBookSessionLocal</local-jndi-name>
</session>
</enterprise-beans>
</openejb-jar>
and finally, in my ejb-jar.xml inside the <entity> I have this:
<resource-ref >
<description><![CDATA[This is a reference to a JDBC
database.]]></description>
<res-ref-name>jdbc/basic/entityDatabase</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Now, the strange thing is that if I deploy the mysql-plan.xml file in
the global scoped fashion, I can write the the database by creating CMP
beans. But if I use the application scoped method, I get the following
error:
22:15:19,898 WARN [SystemExceptionInterceptor] PhoneBookSession
java.lang.NullPointerException
at
org.tranql.sql.DataSourceDelegate.getConnection(DataSourceDelegate.ja
va:36)
at
org.tranql.sql.jdbc.JDBCUpdateCommand.execute(JDBCUpdateCommand.java:
62)
at
org.tranql.cache.SimpleFlushStrategy.flush(SimpleFlushStrategy.java:5
9)
at
org.tranql.cache.SimpleFlushStrategy.flush(SimpleFlushStrategy.java:4
6)
at org.tranql.cache.InTxCache.flush(InTxCache.java:85)
at
org.apache.geronimo.transaction.context.AbstractTransactionContext.fl
ushState(AbstractTransactionContext.java:116)
at
org.apache.geronimo.transaction.context.InheritableTransactionContext
.complete(InheritableTransactionContext.java:172)
at
org.apache.geronimo.transaction.context.InheritableTransactionContext
.commit(InheritableTransactionContext.java:143)
at
org.openejb.transaction.ContainerPolicy$TxRequiresNew.invoke(Containe
rPolicy.java:246)
at
org.openejb.transaction.TransactionContextInterceptor.invoke(Transact
ionContextInterceptor.java:80)
at
org.openejb.slsb.StatelessInstanceInterceptor.invoke(StatelessInstanc
eInterceptor.java:98)
at
org.openejb.transaction.ContainerPolicy$TxRequiresNew.invoke(Containe
rPolicy.java:234)
at
org.openejb.transaction.TransactionContextInterceptor.invoke(Transact...
What am I doing wrong for Application scoping my database configuration?
Thanks in advance, and sorry for all of the cut-n-pasting here.
Cheers.
-Neal
Re: Application Scoped JDBC Connector for CMP
Posted by Neal Sanche <ne...@nsdev.org>.
Jacek Laskowski wrote:
> It would also be worth to point out the sources you used to make them
> up-to-date. Do you happen to remember what pages you consulted which
> happened to be incomplete/conflicting?
Well, Aaron's great M3 developer's guide was one of my references,
specifically the chapter on JDBC Connectors. And also a few other Google
finds:
http://chariotsolutions.com/geronimo/database-deploy.html
http://www-128.ibm.com/developerworks/java/library/j-geron2/
http://openejb.codehaus.org/faq_openejb-jar.html
The document at IBM was where I went off on a tangent, I think.
Cheers.
-Neal
Re: Application Scoped JDBC Connector for CMP
Posted by Jacek Laskowski <jl...@apache.org>.
Neal Sanche wrote:
> I'm just learning from the myriad of complete/incomplete/conflicting documents
> I've been finding scattered around.
Hi Neal,
It would also be worth to point out the sources you used to make them
up-to-date. Do you happen to remember what pages you consulted which
happened to be incomplete/conflicting?
> -Neal
Jacek
Re: Application Scoped JDBC Connector for CMP
Posted by Aaron Mulder <am...@alumni.princeton.edu>.
I'm not sure if a bug report is necessary, but we should probably
try to figure out what went wrong with your previous code. It looked
reasonable on the face of it. We might need more extensive reference
tests. :)
Anyway, when David was talking about not needing the resource-ref,
ley me try to explain. You'd use a resource-ref if you code was going to
look up a DB pool directly, to execute some manual SQL or something. But
you don't need it for CMP. For CMP, the cmp-connection-factory is all you
need to identify the database.
Aaron
On Fri, 17 Jun 2005, Neal Sanche wrote:
> Hi Aaron, and also David,
>
> Thanks again guys. I removed the confusing <resource-ref> elements, and
> added the <resource-link> as you both suggested. And I'm happy to say
> that my application scoped JDBC Datasource is now working nicely.
>
> I'd say that a 'bug report' isn't really necessary here. :) I'm just
> learning from the myriad of complete/incomplete/conflicting documents
> I've been finding scattered around. When I find confusing issues like
> that, I'm sure the best source is to ask here first, and get my facts
> straight.
>
> Thanks so much, guys for the 'light shedding'.
>
> Cheers.
>
> -Neal
>
> Aaron Mulder wrote:
>
> > What happens if you change the cmp-connection-factory in
> >openejb-jar.xml to look like this:
> >
> > <cmp-connection-factory>
> > <resource-link>MysqlDataSource</resource-link>
> > </cmp-connection-factory>
> >
> >Aaron
> >
> >On Fri, 17 Jun 2005, Neal Sanche wrote:
> >
> >
> >>Hi All,
> >>
> >>I'm currently having trouble with a CMP bean getting access to a MySql
> >>database when the deployment plans for the JDBC Connector are
> >>application scoped. Here's what I've done, can you see something wrong
> >>with what I'm doing?
> >>
> >>application.xml
> >>
> >><DEFANGED_application
> >> xmlns="http://java.sun.com/xml/ns/j2ee"
> >> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> >> xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
> >> http://java.sun.com/xml/ns/j2ee/application_1_4.xsd"
> >> version="1.4">
> >> <module>
> >> <ejb>phonebook-ejb.jar</ejb>
> >> </module>
> >> <module>
> >> <web>
> >> <web-uri>phonebook.war</web-uri>
> >> <context-root>/phonebook</context-root>
> >> </web>
> >> </module>
> >> <module>
> >> <connector>tranql-connector-1.0-SNAPSHOT.rar</connector>
> >> </module>
> >></application>
> >>
> >>geronimo-application.xml
> >>
> >><DEFANGED_application
> >> xmlns="http://geronimo.apache.org/xml/ns/j2ee/application"
> >> configId="org/acme/PhoneBook">
> >> <module>
> >> <connector>tranql-connector-1.0-SNAPSHOT.rar</connector>
> >> <alt-dd>mysql-plan.xml</alt-dd>
> >> </module>
> >></application>
> >>
> >>mysql-plan.xml
> >>
> >><connector xmlns="http://geronimo.apache.org/xml/ns/j2ee/connector"
> >> version="1.5" configId="MysqlDatabase"
> >>parentId="org/apache/geronimo/Server">
> >> <dependency>
> >> <uri>mysql/jars/mysql-connector-java-3.1.8-bin.jar</uri>
> >> </dependency>
> >> <resourceadapter>
> >> <outbound-resourceadapter>
> >> <connection-definition>
> >> <connectionfactory-interface> javax.sql.DataSource
> >></connectionfactory-interface>
> >> <connectiondefinition-instance>
> >> <name>MysqlDataSource</name>
> >> <config-property-setting name="UserName"> geronimo
> >></config-property-setting>
> >> <config-property-setting name="Password"> geronimo
> >></config-property-setting>
> >> <config-property-setting name="Driver">
> >>com.mysql.jdbc.Driver </config-property-setting>
> >> <config-property-setting name="ConnectionURL">
> >>jdbc:mysql://localhost/geronimo </config-property-setting>
> >> <config-property-setting
> >>name="CommitBeforeAutocommit"> false </config-property-setting>
> >> <config-property-setting
> >>name="ExceptionSorterClass">
> >>org.tranql.connector.NoExceptionsAreFatalSorter </config-property-setting>
> >> <connectionmanager>
> >> <local-transaction/>
> >> <single-pool>
> >> <max-size>10</max-size>
> >> <min-size>0</min-size>
> >> <blocking-timeout-milliseconds> 5000
> >></blocking-timeout-milliseconds>
> >> <idle-timeout-minutes>30</idle-timeout-minutes>
> >> <match-one/>
> >> </single-pool>
> >> </connectionmanager>
> >> <global-jndi-name> jdbc/MysqlDatabase
> >></global-jndi-name>
> >> </connectiondefinition-instance>
> >> </connection-definition>
> >> </outbound-resourceadapter>
> >> </resourceadapter>
> >></connector>
> >>
> >>openejb-jar.xml
> >>
> >><openejb-jar
> >> xmlns="http://www.openejb.org/xml/ns/openejb-jar"
> >> configId="org/acme/PhonebookEJB"
> >> parentId="MysqlDatabase">
> >> <cmp-connection-factory>
> >> <DEFANGED_application>org/acme/PhoneBook</application>
> >> <module>MysqlDatabase</module>
> >> <name>MysqlDataSource</name>
> >> </cmp-connection-factory>
> >> <enterprise-beans>
> >> <entity>
> >> <ejb-name>PhoneBookEntry</ejb-name>
> >> <jndi-name>PhoneBookEntry</jndi-name>
> >>
> >><local-jndi-name>java:comp/env/ejb/PhoneBookEntryLocal</local-jndi-name>
> >> <table-name>phone</table-name>
> >> <cmp-field-mapping>
> >> <cmp-field-name>name</cmp-field-name>
> >> <table-column>name</table-column>
> >> </cmp-field-mapping>
> >> <cmp-field-mapping>
> >> <cmp-field-name>phoneNumber</cmp-field-name>
> >> <table-column>phone</table-column>
> >> </cmp-field-mapping>
> >> <resource-ref>
> >> <ref-name>jdbc/basic/entityDatabase</ref-name>
> >> <DEFANGED_application>null</application>
> >> <module>MysqlDatabase</module>
> >> <name>PhonebookDBPool</name>
> >> </resource-ref>
> >> </entity>
> >>
> >> <session>
> >> <ejb-name>PhoneBookSession</ejb-name>
> >>
> >><jndi-name>org.acme.phonebook.ejb/PhoneBookSession/Home</jndi-name>
> >>
> >><local-jndi-name>java:comp/env/ejb/PhoneBookSessionLocal</local-jndi-name>
> >> </session>
> >> </enterprise-beans>
> >></openejb-jar>
> >>
> >>and finally, in my ejb-jar.xml inside the <entity> I have this:
> >>
> >> <resource-ref >
> >> <description><![CDATA[This is a reference to a JDBC
> >>database.]]></description>
> >> <res-ref-name>jdbc/basic/entityDatabase</res-ref-name>
> >> <res-type>javax.sql.DataSource</res-type>
> >> <res-auth>Container</res-auth>
> >> </resource-ref>
> >>
> >>Now, the strange thing is that if I deploy the mysql-plan.xml file in
> >>the global scoped fashion, I can write the the database by creating CMP
> >>beans. But if I use the application scoped method, I get the following
> >>error:
> >>
> >>22:15:19,898 WARN [SystemExceptionInterceptor] PhoneBookSession
> >>java.lang.NullPointerException
> >> at
> >>org.tranql.sql.DataSourceDelegate.getConnection(DataSourceDelegate.ja
> >>va:36)
> >> at
> >>org.tranql.sql.jdbc.JDBCUpdateCommand.execute(JDBCUpdateCommand.java:
> >>62)
> >> at
> >>org.tranql.cache.SimpleFlushStrategy.flush(SimpleFlushStrategy.java:5
> >>9)
> >> at
> >>org.tranql.cache.SimpleFlushStrategy.flush(SimpleFlushStrategy.java:4
> >>6)
> >> at org.tranql.cache.InTxCache.flush(InTxCache.java:85)
> >> at
> >>org.apache.geronimo.transaction.context.AbstractTransactionContext.fl
> >>ushState(AbstractTransactionContext.java:116)
> >> at
> >>org.apache.geronimo.transaction.context.InheritableTransactionContext
> >>.complete(InheritableTransactionContext.java:172)
> >> at
> >>org.apache.geronimo.transaction.context.InheritableTransactionContext
> >>.commit(InheritableTransactionContext.java:143)
> >> at
> >>org.openejb.transaction.ContainerPolicy$TxRequiresNew.invoke(Containe
> >>rPolicy.java:246)
> >> at
> >>org.openejb.transaction.TransactionContextInterceptor.invoke(Transact
> >>ionContextInterceptor.java:80)
> >> at
> >>org.openejb.slsb.StatelessInstanceInterceptor.invoke(StatelessInstanc
> >>eInterceptor.java:98)
> >> at
> >>org.openejb.transaction.ContainerPolicy$TxRequiresNew.invoke(Containe
> >>rPolicy.java:234)
> >> at
> >>org.openejb.transaction.TransactionContextInterceptor.invoke(Transact...
> >>
> >>What am I doing wrong for Application scoping my database configuration?
> >>
> >>Thanks in advance, and sorry for all of the cut-n-pasting here.
> >>
> >>Cheers.
> >>
> >>-Neal
> >>
> >>
> >>
> >>
>
>
Re: Application Scoped JDBC Connector for CMP
Posted by Neal Sanche <ne...@nsdev.org>.
Hi Aaron, and also David,
Thanks again guys. I removed the confusing <resource-ref> elements, and
added the <resource-link> as you both suggested. And I'm happy to say
that my application scoped JDBC Datasource is now working nicely.
I'd say that a 'bug report' isn't really necessary here. :) I'm just
learning from the myriad of complete/incomplete/conflicting documents
I've been finding scattered around. When I find confusing issues like
that, I'm sure the best source is to ask here first, and get my facts
straight.
Thanks so much, guys for the 'light shedding'.
Cheers.
-Neal
Aaron Mulder wrote:
> What happens if you change the cmp-connection-factory in
>openejb-jar.xml to look like this:
>
> <cmp-connection-factory>
> <resource-link>MysqlDataSource</resource-link>
> </cmp-connection-factory>
>
>Aaron
>
>On Fri, 17 Jun 2005, Neal Sanche wrote:
>
>
>>Hi All,
>>
>>I'm currently having trouble with a CMP bean getting access to a MySql
>>database when the deployment plans for the JDBC Connector are
>>application scoped. Here's what I've done, can you see something wrong
>>with what I'm doing?
>>
>>application.xml
>>
>><DEFANGED_application
>> xmlns="http://java.sun.com/xml/ns/j2ee"
>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
>> http://java.sun.com/xml/ns/j2ee/application_1_4.xsd"
>> version="1.4">
>> <module>
>> <ejb>phonebook-ejb.jar</ejb>
>> </module>
>> <module>
>> <web>
>> <web-uri>phonebook.war</web-uri>
>> <context-root>/phonebook</context-root>
>> </web>
>> </module>
>> <module>
>> <connector>tranql-connector-1.0-SNAPSHOT.rar</connector>
>> </module>
>></application>
>>
>>geronimo-application.xml
>>
>><DEFANGED_application
>> xmlns="http://geronimo.apache.org/xml/ns/j2ee/application"
>> configId="org/acme/PhoneBook">
>> <module>
>> <connector>tranql-connector-1.0-SNAPSHOT.rar</connector>
>> <alt-dd>mysql-plan.xml</alt-dd>
>> </module>
>></application>
>>
>>mysql-plan.xml
>>
>><connector xmlns="http://geronimo.apache.org/xml/ns/j2ee/connector"
>> version="1.5" configId="MysqlDatabase"
>>parentId="org/apache/geronimo/Server">
>> <dependency>
>> <uri>mysql/jars/mysql-connector-java-3.1.8-bin.jar</uri>
>> </dependency>
>> <resourceadapter>
>> <outbound-resourceadapter>
>> <connection-definition>
>> <connectionfactory-interface> javax.sql.DataSource
>></connectionfactory-interface>
>> <connectiondefinition-instance>
>> <name>MysqlDataSource</name>
>> <config-property-setting name="UserName"> geronimo
>></config-property-setting>
>> <config-property-setting name="Password"> geronimo
>></config-property-setting>
>> <config-property-setting name="Driver">
>>com.mysql.jdbc.Driver </config-property-setting>
>> <config-property-setting name="ConnectionURL">
>>jdbc:mysql://localhost/geronimo </config-property-setting>
>> <config-property-setting
>>name="CommitBeforeAutocommit"> false </config-property-setting>
>> <config-property-setting
>>name="ExceptionSorterClass">
>>org.tranql.connector.NoExceptionsAreFatalSorter </config-property-setting>
>> <connectionmanager>
>> <local-transaction/>
>> <single-pool>
>> <max-size>10</max-size>
>> <min-size>0</min-size>
>> <blocking-timeout-milliseconds> 5000
>></blocking-timeout-milliseconds>
>> <idle-timeout-minutes>30</idle-timeout-minutes>
>> <match-one/>
>> </single-pool>
>> </connectionmanager>
>> <global-jndi-name> jdbc/MysqlDatabase
>></global-jndi-name>
>> </connectiondefinition-instance>
>> </connection-definition>
>> </outbound-resourceadapter>
>> </resourceadapter>
>></connector>
>>
>>openejb-jar.xml
>>
>><openejb-jar
>> xmlns="http://www.openejb.org/xml/ns/openejb-jar"
>> configId="org/acme/PhonebookEJB"
>> parentId="MysqlDatabase">
>> <cmp-connection-factory>
>> <DEFANGED_application>org/acme/PhoneBook</application>
>> <module>MysqlDatabase</module>
>> <name>MysqlDataSource</name>
>> </cmp-connection-factory>
>> <enterprise-beans>
>> <entity>
>> <ejb-name>PhoneBookEntry</ejb-name>
>> <jndi-name>PhoneBookEntry</jndi-name>
>>
>><local-jndi-name>java:comp/env/ejb/PhoneBookEntryLocal</local-jndi-name>
>> <table-name>phone</table-name>
>> <cmp-field-mapping>
>> <cmp-field-name>name</cmp-field-name>
>> <table-column>name</table-column>
>> </cmp-field-mapping>
>> <cmp-field-mapping>
>> <cmp-field-name>phoneNumber</cmp-field-name>
>> <table-column>phone</table-column>
>> </cmp-field-mapping>
>> <resource-ref>
>> <ref-name>jdbc/basic/entityDatabase</ref-name>
>> <DEFANGED_application>null</application>
>> <module>MysqlDatabase</module>
>> <name>PhonebookDBPool</name>
>> </resource-ref>
>> </entity>
>>
>> <session>
>> <ejb-name>PhoneBookSession</ejb-name>
>>
>><jndi-name>org.acme.phonebook.ejb/PhoneBookSession/Home</jndi-name>
>>
>><local-jndi-name>java:comp/env/ejb/PhoneBookSessionLocal</local-jndi-name>
>> </session>
>> </enterprise-beans>
>></openejb-jar>
>>
>>and finally, in my ejb-jar.xml inside the <entity> I have this:
>>
>> <resource-ref >
>> <description><![CDATA[This is a reference to a JDBC
>>database.]]></description>
>> <res-ref-name>jdbc/basic/entityDatabase</res-ref-name>
>> <res-type>javax.sql.DataSource</res-type>
>> <res-auth>Container</res-auth>
>> </resource-ref>
>>
>>Now, the strange thing is that if I deploy the mysql-plan.xml file in
>>the global scoped fashion, I can write the the database by creating CMP
>>beans. But if I use the application scoped method, I get the following
>>error:
>>
>>22:15:19,898 WARN [SystemExceptionInterceptor] PhoneBookSession
>>java.lang.NullPointerException
>> at
>>org.tranql.sql.DataSourceDelegate.getConnection(DataSourceDelegate.ja
>>va:36)
>> at
>>org.tranql.sql.jdbc.JDBCUpdateCommand.execute(JDBCUpdateCommand.java:
>>62)
>> at
>>org.tranql.cache.SimpleFlushStrategy.flush(SimpleFlushStrategy.java:5
>>9)
>> at
>>org.tranql.cache.SimpleFlushStrategy.flush(SimpleFlushStrategy.java:4
>>6)
>> at org.tranql.cache.InTxCache.flush(InTxCache.java:85)
>> at
>>org.apache.geronimo.transaction.context.AbstractTransactionContext.fl
>>ushState(AbstractTransactionContext.java:116)
>> at
>>org.apache.geronimo.transaction.context.InheritableTransactionContext
>>.complete(InheritableTransactionContext.java:172)
>> at
>>org.apache.geronimo.transaction.context.InheritableTransactionContext
>>.commit(InheritableTransactionContext.java:143)
>> at
>>org.openejb.transaction.ContainerPolicy$TxRequiresNew.invoke(Containe
>>rPolicy.java:246)
>> at
>>org.openejb.transaction.TransactionContextInterceptor.invoke(Transact
>>ionContextInterceptor.java:80)
>> at
>>org.openejb.slsb.StatelessInstanceInterceptor.invoke(StatelessInstanc
>>eInterceptor.java:98)
>> at
>>org.openejb.transaction.ContainerPolicy$TxRequiresNew.invoke(Containe
>>rPolicy.java:234)
>> at
>>org.openejb.transaction.TransactionContextInterceptor.invoke(Transact...
>>
>>What am I doing wrong for Application scoping my database configuration?
>>
>>Thanks in advance, and sorry for all of the cut-n-pasting here.
>>
>>Cheers.
>>
>>-Neal
>>
>>
>>
>>
Re: Application Scoped JDBC Connector for CMP
Posted by Aaron Mulder <am...@alumni.princeton.edu>.
What happens if you change the cmp-connection-factory in
openejb-jar.xml to look like this:
<cmp-connection-factory>
<resource-link>MysqlDataSource</resource-link>
</cmp-connection-factory>
Aaron
On Fri, 17 Jun 2005, Neal Sanche wrote:
> Hi All,
>
> I'm currently having trouble with a CMP bean getting access to a MySql
> database when the deployment plans for the JDBC Connector are
> application scoped. Here's what I've done, can you see something wrong
> with what I'm doing?
>
> application.xml
>
> <application
> xmlns="http://java.sun.com/xml/ns/j2ee"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
> http://java.sun.com/xml/ns/j2ee/application_1_4.xsd"
> version="1.4">
> <module>
> <ejb>phonebook-ejb.jar</ejb>
> </module>
> <module>
> <web>
> <web-uri>phonebook.war</web-uri>
> <context-root>/phonebook</context-root>
> </web>
> </module>
> <module>
> <connector>tranql-connector-1.0-SNAPSHOT.rar</connector>
> </module>
> </application>
>
> geronimo-application.xml
>
> <application
> xmlns="http://geronimo.apache.org/xml/ns/j2ee/application"
> configId="org/acme/PhoneBook">
> <module>
> <connector>tranql-connector-1.0-SNAPSHOT.rar</connector>
> <alt-dd>mysql-plan.xml</alt-dd>
> </module>
> </application>
>
> mysql-plan.xml
>
> <connector xmlns="http://geronimo.apache.org/xml/ns/j2ee/connector"
> version="1.5" configId="MysqlDatabase"
> parentId="org/apache/geronimo/Server">
> <dependency>
> <uri>mysql/jars/mysql-connector-java-3.1.8-bin.jar</uri>
> </dependency>
> <resourceadapter>
> <outbound-resourceadapter>
> <connection-definition>
> <connectionfactory-interface> javax.sql.DataSource
> </connectionfactory-interface>
> <connectiondefinition-instance>
> <name>MysqlDataSource</name>
> <config-property-setting name="UserName"> geronimo
> </config-property-setting>
> <config-property-setting name="Password"> geronimo
> </config-property-setting>
> <config-property-setting name="Driver">
> com.mysql.jdbc.Driver </config-property-setting>
> <config-property-setting name="ConnectionURL">
> jdbc:mysql://localhost/geronimo </config-property-setting>
> <config-property-setting
> name="CommitBeforeAutocommit"> false </config-property-setting>
> <config-property-setting
> name="ExceptionSorterClass">
> org.tranql.connector.NoExceptionsAreFatalSorter </config-property-setting>
> <connectionmanager>
> <local-transaction/>
> <single-pool>
> <max-size>10</max-size>
> <min-size>0</min-size>
> <blocking-timeout-milliseconds> 5000
> </blocking-timeout-milliseconds>
> <idle-timeout-minutes>30</idle-timeout-minutes>
> <match-one/>
> </single-pool>
> </connectionmanager>
> <global-jndi-name> jdbc/MysqlDatabase
> </global-jndi-name>
> </connectiondefinition-instance>
> </connection-definition>
> </outbound-resourceadapter>
> </resourceadapter>
> </connector>
>
> openejb-jar.xml
>
> <openejb-jar
> xmlns="http://www.openejb.org/xml/ns/openejb-jar"
> configId="org/acme/PhonebookEJB"
> parentId="MysqlDatabase">
> <cmp-connection-factory>
> <application>org/acme/PhoneBook</application>
> <module>MysqlDatabase</module>
> <name>MysqlDataSource</name>
> </cmp-connection-factory>
> <enterprise-beans>
> <entity>
> <ejb-name>PhoneBookEntry</ejb-name>
> <jndi-name>PhoneBookEntry</jndi-name>
>
> <local-jndi-name>java:comp/env/ejb/PhoneBookEntryLocal</local-jndi-name>
> <table-name>phone</table-name>
> <cmp-field-mapping>
> <cmp-field-name>name</cmp-field-name>
> <table-column>name</table-column>
> </cmp-field-mapping>
> <cmp-field-mapping>
> <cmp-field-name>phoneNumber</cmp-field-name>
> <table-column>phone</table-column>
> </cmp-field-mapping>
> <resource-ref>
> <ref-name>jdbc/basic/entityDatabase</ref-name>
> <application>null</application>
> <module>MysqlDatabase</module>
> <name>PhonebookDBPool</name>
> </resource-ref>
> </entity>
>
> <session>
> <ejb-name>PhoneBookSession</ejb-name>
>
> <jndi-name>org.acme.phonebook.ejb/PhoneBookSession/Home</jndi-name>
>
> <local-jndi-name>java:comp/env/ejb/PhoneBookSessionLocal</local-jndi-name>
> </session>
> </enterprise-beans>
> </openejb-jar>
>
> and finally, in my ejb-jar.xml inside the <entity> I have this:
>
> <resource-ref >
> <description><![CDATA[This is a reference to a JDBC
> database.]]></description>
> <res-ref-name>jdbc/basic/entityDatabase</res-ref-name>
> <res-type>javax.sql.DataSource</res-type>
> <res-auth>Container</res-auth>
> </resource-ref>
>
> Now, the strange thing is that if I deploy the mysql-plan.xml file in
> the global scoped fashion, I can write the the database by creating CMP
> beans. But if I use the application scoped method, I get the following
> error:
>
> 22:15:19,898 WARN [SystemExceptionInterceptor] PhoneBookSession
> java.lang.NullPointerException
> at
> org.tranql.sql.DataSourceDelegate.getConnection(DataSourceDelegate.ja
> va:36)
> at
> org.tranql.sql.jdbc.JDBCUpdateCommand.execute(JDBCUpdateCommand.java:
> 62)
> at
> org.tranql.cache.SimpleFlushStrategy.flush(SimpleFlushStrategy.java:5
> 9)
> at
> org.tranql.cache.SimpleFlushStrategy.flush(SimpleFlushStrategy.java:4
> 6)
> at org.tranql.cache.InTxCache.flush(InTxCache.java:85)
> at
> org.apache.geronimo.transaction.context.AbstractTransactionContext.fl
> ushState(AbstractTransactionContext.java:116)
> at
> org.apache.geronimo.transaction.context.InheritableTransactionContext
> .complete(InheritableTransactionContext.java:172)
> at
> org.apache.geronimo.transaction.context.InheritableTransactionContext
> .commit(InheritableTransactionContext.java:143)
> at
> org.openejb.transaction.ContainerPolicy$TxRequiresNew.invoke(Containe
> rPolicy.java:246)
> at
> org.openejb.transaction.TransactionContextInterceptor.invoke(Transact
> ionContextInterceptor.java:80)
> at
> org.openejb.slsb.StatelessInstanceInterceptor.invoke(StatelessInstanc
> eInterceptor.java:98)
> at
> org.openejb.transaction.ContainerPolicy$TxRequiresNew.invoke(Containe
> rPolicy.java:234)
> at
> org.openejb.transaction.TransactionContextInterceptor.invoke(Transact...
>
> What am I doing wrong for Application scoping my database configuration?
>
> Thanks in advance, and sorry for all of the cut-n-pasting here.
>
> Cheers.
>
> -Neal
>
>
Re: Application Scoped JDBC Connector for CMP
Posted by Neal Sanche <ne...@nsdev.org>.
Hi David,
You question my use of the resource-ref to the db in my ejb-jar.xml, and
again in the openejb-jar.xml... I was following a document online trying
to get my CMP stuff working. I'll try without them now that you and
Aaron have given me the <resource-link> clue. I'll let you know if it
works without those. I'm getting closer now.
Thanks.
-Neal
David Jencks wrote:
> I'm a bit confused... some parts of your plans seem to imply the
> connector is outside the ear and some parts imply it is in the ear.
> And, why does a cmp bean need a resource-ref to the db the cmp engine
> is using...??? Well, there might be reasons.
>
> but, anyway, I recommend you replace your name specifications with
> <resource-link> MysqlDataSource </resource-link> (no app, module,
> name specification). Geronimo should find the datasource whether
> you include it in the ear or deploy it standalone. It won't find it
> if you deploy it in a different ear :-)
>
> the alt-dd stuff has not been tested AFAIK. If the above doesn't
> work, please try putting all the plans (openejb and connector) into
> the geronimo-application plan and see if that helps: if so please
> file a bug.
>
> Hope this helps
> david jencks
>
> On Jun 17, 2005, at 9:30 PM, Neal Sanche wrote:
>
>> Hi All,
>>
>> I'm currently having trouble with a CMP bean getting access to a
>> MySql database when the deployment plans for the JDBC Connector are
>> application scoped. Here's what I've done, can you see something
>> wrong with what I'm doing?
>>
>> application.xml
>>
>> <DEFANGED_application
>> xmlns="http://java.sun.com/xml/ns/j2ee"
>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
>> http://java.sun.com/xml/ns/j2ee/application_1_4.xsd"
>> version="1.4">
>> <module>
>> <ejb>phonebook-ejb.jar</ejb>
>> </module>
>> <module>
>> <web>
>> <web-uri>phonebook.war</web-uri>
>> <context-root>/phonebook</context-root>
>> </web>
>> </module>
>> <module>
>> <connector>tranql-connector-1.0-SNAPSHOT.rar</connector>
>> </module>
>> </application>
>>
>> geronimo-application.xml
>>
>> <DEFANGED_application
>> xmlns="http://geronimo.apache.org/xml/ns/j2ee/application"
>> configId="org/acme/PhoneBook">
>> <module>
>> <connector>tranql-connector-1.0-SNAPSHOT.rar</connector>
>> <alt-dd>mysql-plan.xml</alt-dd>
>> </module>
>> </application>
>>
>> mysql-plan.xml
>>
>> <connector xmlns="http://geronimo.apache.org/xml/ns/j2ee/connector"
>> version="1.5" configId="MysqlDatabase"
>> parentId="org/apache/geronimo/Server">
>> <dependency>
>> <uri>mysql/jars/mysql-connector-java-3.1.8-bin.jar</uri>
>> </dependency>
>> <resourceadapter>
>> <outbound-resourceadapter>
>> <connection-definition>
>> <connectionfactory-interface> javax.sql.DataSource
>> </connectionfactory-interface>
>> <connectiondefinition-instance>
>> <name>MysqlDataSource</name>
>> <config-property-setting name="UserName">
>> geronimo </config-property-setting>
>> <config-property-setting name="Password">
>> geronimo </config-property-setting>
>> <config-property-setting name="Driver">
>> com.mysql.jdbc.Driver </config-property-setting>
>> <config-property-setting name="ConnectionURL">
>> jdbc:mysql://localhost/geronimo </config-property-setting>
>> <config-property-setting
>> name="CommitBeforeAutocommit"> false </config-property-setting>
>> <config-property-setting
>> name="ExceptionSorterClass">
>> org.tranql.connector.NoExceptionsAreFatalSorter
>> </config-property-setting>
>> <connectionmanager>
>> <local-transaction/>
>> <single-pool>
>> <max-size>10</max-size>
>> <min-size>0</min-size>
>> <blocking-timeout-milliseconds> 5000
>> </blocking-timeout-milliseconds>
>>
>> <idle-timeout-minutes>30</idle-timeout-minutes>
>> <match-one/>
>> </single-pool>
>> </connectionmanager>
>> <global-jndi-name> jdbc/MysqlDatabase
>> </global-jndi-name>
>> </connectiondefinition-instance>
>> </connection-definition>
>> </outbound-resourceadapter>
>> </resourceadapter>
>> </connector>
>>
>> openejb-jar.xml
>>
>> <openejb-jar
>> xmlns="http://www.openejb.org/xml/ns/openejb-jar"
>> configId="org/acme/PhonebookEJB"
>> parentId="MysqlDatabase">
>> <cmp-connection-factory>
>> <DEFANGED_application>org/acme/PhoneBook</application>
>> <module>MysqlDatabase</module>
>> <name>MysqlDataSource</name>
>> </cmp-connection-factory>
>> <enterprise-beans>
>> <entity>
>> <ejb-name>PhoneBookEntry</ejb-name>
>> <jndi-name>PhoneBookEntry</jndi-name>
>>
>> <local-jndi-name>java:comp/env/ejb/PhoneBookEntryLocal</local-jndi-
>> name>
>> <table-name>phone</table-name>
>> <cmp-field-mapping>
>> <cmp-field-name>name</cmp-field-name>
>> <table-column>name</table-column>
>> </cmp-field-mapping>
>> <cmp-field-mapping>
>> <cmp-field-name>phoneNumber</cmp-field-name>
>> <table-column>phone</table-column>
>> </cmp-field-mapping>
>> <resource-ref>
>> <ref-name>jdbc/basic/entityDatabase</ref-name>
>> <DEFANGED_application>null</application>
>> <module>MysqlDatabase</module>
>> <name>PhonebookDBPool</name>
>> </resource-ref>
>> </entity>
>>
>> <session>
>> <ejb-name>PhoneBookSession</ejb-name>
>>
>> <jndi-name>org.acme.phonebook.ejb/PhoneBookSession/Home</jndi-name>
>>
>> <local-jndi-name>java:comp/env/ejb/PhoneBookSessionLocal</local-jndi-
>> name>
>> </session>
>> </enterprise-beans>
>> </openejb-jar>
>>
>> and finally, in my ejb-jar.xml inside the <entity> I have this:
>>
>> <resource-ref >
>> <description><![CDATA[This is a reference to a JDBC
>> database.]]></description>
>> <res-ref-name>jdbc/basic/entityDatabase</res-ref-name>
>> <res-type>javax.sql.DataSource</res-type>
>> <res-auth>Container</res-auth>
>> </resource-ref>
>>
>> Now, the strange thing is that if I deploy the mysql-plan.xml file
>> in the global scoped fashion, I can write the the database by
>> creating CMP beans. But if I use the application scoped method, I
>> get the following error:
>>
>> 22:15:19,898 WARN [SystemExceptionInterceptor] PhoneBookSession
>> java.lang.NullPointerException
>> at
>> org.tranql.sql.DataSourceDelegate.getConnection(DataSourceDelegate.ja
>> va:36)
>> at
>> org.tranql.sql.jdbc.JDBCUpdateCommand.execute(JDBCUpdateCommand.java:
>> 62)
>> at
>> org.tranql.cache.SimpleFlushStrategy.flush(SimpleFlushStrategy.java:5
>> 9)
>> at
>> org.tranql.cache.SimpleFlushStrategy.flush(SimpleFlushStrategy.java:4
>> 6)
>> at org.tranql.cache.InTxCache.flush(InTxCache.java:85)
>> at
>> org.apache.geronimo.transaction.context.AbstractTransactionContext.fl
>> ushState(AbstractTransactionContext.java:116)
>> at
>> org.apache.geronimo.transaction.context.InheritableTransactionContext
>> .complete(InheritableTransactionContext.java:172)
>> at
>> org.apache.geronimo.transaction.context.InheritableTransactionContext
>> .commit(InheritableTransactionContext.java:143)
>> at
>> org.openejb.transaction.ContainerPolicy$TxRequiresNew.invoke(Containe
>> rPolicy.java:246)
>> at
>> org.openejb.transaction.TransactionContextInterceptor.invoke(Transact
>> ionContextInterceptor.java:80)
>> at
>> org.openejb.slsb.StatelessInstanceInterceptor.invoke(StatelessInstanc
>> eInterceptor.java:98)
>> at
>> org.openejb.transaction.ContainerPolicy$TxRequiresNew.invoke(Containe
>> rPolicy.java:234)
>> at
>> org.openejb.transaction.TransactionContextInterceptor.invoke(Transact..
>> .
>>
>> What am I doing wrong for Application scoping my database
>> configuration?
>>
>> Thanks in advance, and sorry for all of the cut-n-pasting here.
>>
>> Cheers.
>>
>> -Neal
>>
Re: Application Scoped JDBC Connector for CMP
Posted by David Jencks <da...@yahoo.com>.
I'm a bit confused... some parts of your plans seem to imply the
connector is outside the ear and some parts imply it is in the ear.
And, why does a cmp bean need a resource-ref to the db the cmp engine
is using...??? Well, there might be reasons.
but, anyway, I recommend you replace your name specifications with
<resource-link> MysqlDataSource </resource-link> (no app, module, name
specification). Geronimo should find the datasource whether you
include it in the ear or deploy it standalone. It won't find it if you
deploy it in a different ear :-)
the alt-dd stuff has not been tested AFAIK. If the above doesn't work,
please try putting all the plans (openejb and connector) into the
geronimo-application plan and see if that helps: if so please file a
bug.
Hope this helps
david jencks
On Jun 17, 2005, at 9:30 PM, Neal Sanche wrote:
> Hi All,
>
> I'm currently having trouble with a CMP bean getting access to a MySql
> database when the deployment plans for the JDBC Connector are
> application scoped. Here's what I've done, can you see something wrong
> with what I'm doing?
>
> application.xml
>
> <application
> xmlns="http://java.sun.com/xml/ns/j2ee"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
> http://java.sun.com/xml/ns/j2ee/application_1_4.xsd"
> version="1.4">
> <module>
> <ejb>phonebook-ejb.jar</ejb>
> </module>
> <module>
> <web>
> <web-uri>phonebook.war</web-uri>
> <context-root>/phonebook</context-root>
> </web>
> </module>
> <module>
> <connector>tranql-connector-1.0-SNAPSHOT.rar</connector>
> </module>
> </application>
>
> geronimo-application.xml
>
> <application
> xmlns="http://geronimo.apache.org/xml/ns/j2ee/application"
> configId="org/acme/PhoneBook">
> <module>
> <connector>tranql-connector-1.0-SNAPSHOT.rar</connector>
> <alt-dd>mysql-plan.xml</alt-dd>
> </module>
> </application>
>
> mysql-plan.xml
>
> <connector xmlns="http://geronimo.apache.org/xml/ns/j2ee/connector"
> version="1.5" configId="MysqlDatabase"
> parentId="org/apache/geronimo/Server">
> <dependency>
> <uri>mysql/jars/mysql-connector-java-3.1.8-bin.jar</uri>
> </dependency>
> <resourceadapter>
> <outbound-resourceadapter>
> <connection-definition>
> <connectionfactory-interface> javax.sql.DataSource
> </connectionfactory-interface>
> <connectiondefinition-instance>
> <name>MysqlDataSource</name>
> <config-property-setting name="UserName"> geronimo
> </config-property-setting>
> <config-property-setting name="Password"> geronimo
> </config-property-setting>
> <config-property-setting name="Driver">
> com.mysql.jdbc.Driver </config-property-setting>
> <config-property-setting name="ConnectionURL">
> jdbc:mysql://localhost/geronimo </config-property-setting>
> <config-property-setting
> name="CommitBeforeAutocommit"> false </config-property-setting>
> <config-property-setting
> name="ExceptionSorterClass">
> org.tranql.connector.NoExceptionsAreFatalSorter
> </config-property-setting>
> <connectionmanager>
> <local-transaction/>
> <single-pool>
> <max-size>10</max-size>
> <min-size>0</min-size>
> <blocking-timeout-milliseconds> 5000
> </blocking-timeout-milliseconds>
>
> <idle-timeout-minutes>30</idle-timeout-minutes>
> <match-one/>
> </single-pool>
> </connectionmanager>
> <global-jndi-name> jdbc/MysqlDatabase
> </global-jndi-name>
> </connectiondefinition-instance>
> </connection-definition>
> </outbound-resourceadapter>
> </resourceadapter>
> </connector>
>
> openejb-jar.xml
>
> <openejb-jar
> xmlns="http://www.openejb.org/xml/ns/openejb-jar"
> configId="org/acme/PhonebookEJB"
> parentId="MysqlDatabase">
> <cmp-connection-factory>
> <application>org/acme/PhoneBook</application>
> <module>MysqlDatabase</module>
> <name>MysqlDataSource</name>
> </cmp-connection-factory>
> <enterprise-beans>
> <entity>
> <ejb-name>PhoneBookEntry</ejb-name>
> <jndi-name>PhoneBookEntry</jndi-name>
>
> <local-jndi-name>java:comp/env/ejb/PhoneBookEntryLocal</local-jndi-
> name>
> <table-name>phone</table-name>
> <cmp-field-mapping>
> <cmp-field-name>name</cmp-field-name>
> <table-column>name</table-column>
> </cmp-field-mapping>
> <cmp-field-mapping>
> <cmp-field-name>phoneNumber</cmp-field-name>
> <table-column>phone</table-column>
> </cmp-field-mapping>
> <resource-ref>
> <ref-name>jdbc/basic/entityDatabase</ref-name>
> <application>null</application>
> <module>MysqlDatabase</module>
> <name>PhonebookDBPool</name>
> </resource-ref>
> </entity>
>
> <session>
> <ejb-name>PhoneBookSession</ejb-name>
>
> <jndi-name>org.acme.phonebook.ejb/PhoneBookSession/Home</jndi-name>
>
> <local-jndi-name>java:comp/env/ejb/PhoneBookSessionLocal</local-jndi-
> name>
> </session>
> </enterprise-beans>
> </openejb-jar>
>
> and finally, in my ejb-jar.xml inside the <entity> I have this:
>
> <resource-ref >
> <description><![CDATA[This is a reference to a JDBC
> database.]]></description>
> <res-ref-name>jdbc/basic/entityDatabase</res-ref-name>
> <res-type>javax.sql.DataSource</res-type>
> <res-auth>Container</res-auth>
> </resource-ref>
>
> Now, the strange thing is that if I deploy the mysql-plan.xml file in
> the global scoped fashion, I can write the the database by creating
> CMP beans. But if I use the application scoped method, I get the
> following error:
>
> 22:15:19,898 WARN [SystemExceptionInterceptor] PhoneBookSession
> java.lang.NullPointerException
> at
> org.tranql.sql.DataSourceDelegate.getConnection(DataSourceDelegate.ja
> va:36)
> at
> org.tranql.sql.jdbc.JDBCUpdateCommand.execute(JDBCUpdateCommand.java:
> 62)
> at
> org.tranql.cache.SimpleFlushStrategy.flush(SimpleFlushStrategy.java:5
> 9)
> at
> org.tranql.cache.SimpleFlushStrategy.flush(SimpleFlushStrategy.java:4
> 6)
> at org.tranql.cache.InTxCache.flush(InTxCache.java:85)
> at
> org.apache.geronimo.transaction.context.AbstractTransactionContext.fl
> ushState(AbstractTransactionContext.java:116)
> at
> org.apache.geronimo.transaction.context.InheritableTransactionContext
> .complete(InheritableTransactionContext.java:172)
> at
> org.apache.geronimo.transaction.context.InheritableTransactionContext
> .commit(InheritableTransactionContext.java:143)
> at
> org.openejb.transaction.ContainerPolicy$TxRequiresNew.invoke(Containe
> rPolicy.java:246)
> at
> org.openejb.transaction.TransactionContextInterceptor.invoke(Transact
> ionContextInterceptor.java:80)
> at
> org.openejb.slsb.StatelessInstanceInterceptor.invoke(StatelessInstanc
> eInterceptor.java:98)
> at
> org.openejb.transaction.ContainerPolicy$TxRequiresNew.invoke(Containe
> rPolicy.java:234)
> at
> org.openejb.transaction.TransactionContextInterceptor.invoke(Transact..
> .
>
> What am I doing wrong for Application scoping my database
> configuration?
>
> Thanks in advance, and sorry for all of the cut-n-pasting here.
>
> Cheers.
>
> -Neal
>