You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Per Newgro <pe...@gmx.ch> on 2006/12/05 09:22:02 UTC

Two datasources - one database

Hi *,

i try to port my application from jboss to openejb to use it as a standalone 
version. David Blevis already helped alot on my other issue:
  HOWTO OpenEJB and HSqlDB

He noticed me to add the following lines to my ejb-jar.xml file
>       <session>
>          ...
>             <resource-ref>
>                 <res-ref-name>APPLDB</res-ref-name>
>                 <res-type>javax.sql.DataSource</res-type>
>                 <res-auth>Container</res-auth>
>             </resource-ref>
>             <resource-ref>
>                 <res-ref-name>APPLDBnoTx</res-ref-name>
>                 <res-type>javax.sql.DataSource</res-type>
>                 <res-auth>Container</res-auth>
>             </resource-ref>
>       </session>

One of his comments was:
>  On a slightly different note, I'm curious why you'd have two  
>  connectors with the exact same configuration

And now i have my problem with exactly this issue. Access to the APPLDB is 
working by lookup("java:comp/env/APPLDB"). But if i try to access the no 
transaction datasource by lookup("java:comp/env/APPLDBnoTx") i get a 
javax.naming.NameNotFoundException: Name "java:comp/env/APPLDBnoTx" not found.

Is there an issue in ejb spec that i cant access same database by usage of 
different datasources?

PS: As the underlying database i use apaches derby (latest version)

Cheers
Per

Re: Two datasources - one database

Posted by David Blevins <da...@visi.com>.
On Dec 5, 2006, at 11:28 AM, Per Newgro wrote:

> Thank you for reply. I've got it already working. I setup the whole  
> system
> again. After that everything works fine. I think it was a  
> configuration fault
> of myown.

Excellent!

If anything else comes up, don't hesitate to post.

-David


Re: Two datasources - one database

Posted by Per Newgro <pe...@gmx.ch>.
Thank you for reply. I've got it already working. I setup the whole system 
again. After that everything works fine. I think it was a configuration fault 
of myown.

Cheers
Per

Re: Two datasources - one database

Posted by David Blevins <da...@visi.com>.
On Dec 5, 2006, at 12:22 AM, Per Newgro wrote:

> Hi *,
>
> i try to port my application from jboss to openejb to use it as a  
> standalone
> version. David Blevins already helped alot on my other issue:
>   HOWTO OpenEJB and HSqlDB
>
> He noticed me to add the following lines to my ejb-jar.xml file
>>       <session>
>>          ...
>>             <resource-ref>
>>                 <res-ref-name>APPLDB</res-ref-name>
>>                 <res-type>javax.sql.DataSource</res-type>
>>                 <res-auth>Container</res-auth>
>>             </resource-ref>
>>             <resource-ref>
>>                 <res-ref-name>APPLDBnoTx</res-ref-name>
>>                 <res-type>javax.sql.DataSource</res-type>
>>                 <res-auth>Container</res-auth>
>>             </resource-ref>
>>       </session>
>
> One of his comments was:
>>  On a slightly different note, I'm curious why you'd have two
>>  connectors with the exact same configuration
>
> And now i have my problem with exactly this issue. Access to the  
> APPLDB is
> working by lookup("java:comp/env/APPLDB"). But if i try to access  
> the no
> transaction datasource by lookup("java:comp/env/APPLDBnoTx") i get a
> javax.naming.NameNotFoundException: Name "java:comp/env/APPLDBnoTx"  
> not found.
>
> Is there an issue in ejb spec that i cant access same database by  
> usage of
> different datasources?

This should work fine.  I saw your config file, your openejb-jar.xml  
file and they were spot on.

Essentially they were:

openejb.conf:
  <openejb>
     ...
     <Connector id="APPLDB">...</Connector>
     <Connector id="APPLDBnoTx">...</Connector>
     ...
  </openejb>

openejb-jar.xml:
  ...
   <ejb-deployment ... >
     <resource-link res-ref-name="APPLDB" res-id="APPLDB"/>
     <resource-link res-ref-name="APPLDBnoTx" res-id="APPLDBnoTx"/>
   </ejb-deployment>
  ...

And of course the ejb-jar.xml you post above with the two resource- 
ref elements whose names are "<res-ref-name>APPLDB" and "<res-ref- 
name>APPLDBnoTx".

This should be working.  What you have is exactly right (unless I'm  
missing something too obvious)

First thing you'll want to check is to make sure you are doing the  
lookup the ExportDatabaseUC bean and not some other bean.

Also definitely check or post your log file for anything suspicious.

-David


Re: Two datasources - one database

Posted by Dain Sundstrom <da...@iq80.com>.
On Dec 5, 2006, at 12:22 AM, Per Newgro wrote:

> He noticed me to add the following lines to my ejb-jar.xml file
>>       <session>
>>          ...
>>             <resource-ref>
>>                 <res-ref-name>APPLDB</res-ref-name>
>>                 <res-type>javax.sql.DataSource</res-type>
>>                 <res-auth>Container</res-auth>
>>             </resource-ref>
>>             <resource-ref>
>>                 <res-ref-name>APPLDBnoTx</res-ref-name>
>>                 <res-type>javax.sql.DataSource</res-type>
>>                 <res-auth>Container</res-auth>
>>             </resource-ref>
>>       </session>
>
> One of his comments was:
>>  On a slightly different note, I'm curious why you'd have two
>>  connectors with the exact same configuration

To answer David's question, the first data source is connected to JTA  
and therefore the setAutocommit and commit methods shouldn't be  
called.  The second data source is a not connected to JTA and is  
using resource local transactions.

> And now i have my problem with exactly this issue. Access to the  
> APPLDB is
> working by lookup("java:comp/env/APPLDB"). But if i try to access  
> the no
> transaction datasource by lookup("java:comp/env/APPLDBnoTx") i get a
> javax.naming.NameNotFoundException: Name "java:comp/env/APPLDBnoTx"  
> not found.

I'm not sure on the details of how you do this with OpenEJB, but  
you'll need to declare another database connector and map your  
resource-ref to that connector.  Hopefully, David or someone else  
will fill in the details :)

> Is there an issue in ejb spec that i cant access same database by  
> usage of
> different datasources?

Nope.  What you are doing is perfectly legal and quite common.

-dain