You need to do something like:
Add the following to your ejb-jar.xml for both beans:
<session>
...
<transaction-type>Bean</transaction-type>
<resource-ref>
<res-ref-name>jdbc/UsageDS </res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</session>
and this to jboss.xml, which maps the hardcoded logical name to a
physical name
<session>
<ejb-name> UsageLive </ejb-name>
...
<resource-ref>
<res-ref-name>jdbc/UsageDS </res-ref-name>
<resource-name>jdbc/UsageLiveDS</resource-name>
</resource-ref>
</session>
<session>
<ejb-name> UsageWarehouse </ejb-name>
...
<resource-ref>
<res-ref-name>jdbc/UsageDS </res-ref-name>
<resource-name>jdbc/UsageWarehouseDS </resource-name>
</resource-ref>
</session>
and this to jbosscmp-jdbc.xml:
<resource-managers>
<resource-manager>
<res-name>jdbc/UsageLiveDS </res-name>
<res-jndi-name>java:UsageLiveDS</res-jndi-name>
</resource-manager>
<resource-manager>
<res-name>jdbc/UsageWarehouseDS </res-name>
<res-jndi-name>java:UsageWarehouseDS</res-jndi-name>
</resource-manager>
</resource-managers>
In your code, you lookup the datasource in your bean's ENC:
java:comp/env/jdbc/UsageDS
There's more info in the dtd's for these xml files.
When properly setup, you can see the resource refs for you beans in the
JBoss JNDIView.
On Friday, June 7, 2002, at 09:24 AM, David Brady wrote:
>
> I have a live database which is kept up-to-date with system usage
> information from the last hour. Data older than an hour is moved to a
> warehouse database.
>
> A stateless bean (call it UsageBean) already exists which reads data
> from the live database. I'd like to be able to use the same bean
> (kinda!), etc to read the data from the warehouse.
>
> I've already created two datasources: UsageLiveDS, and UsageWarehouseDS.
>
> My initial thought was to handle this all through manipulating ejb-
> jar.xml, and jboss.xml - creating an ejb called UsageLive, and
> UsageWarehouse.
>
> ejb-jar.xml
>
> <session>
> <ejb-name>UsageLive</ejb-name>
> <home>UsageHome</home>
> <remote>Usage</remote>
> <ejb-class>UsageBean</ejb-class>
> <session-type>Stateless</session-type>
> <transaction-type>Bean</transaction-type>
> </session>
>
> <session>
> <ejb-name>UsageWarehouse</ejb-name>
> <home>UsageHome</home>
> <remote>Usage</remote>
> <ejb-class>UsageBean</ejb-class>
> <session-type>Stateless</session-type>
> <transaction-type>Bean</transaction-type>
> </session>
>
> And somehow (somewhere) map the datasources appropriately. But I'm
> having a conceptual block on how to make this work 'cause of how I get
> connections in UsageBean:
>
> InitialContext initialCtx = new InitialContext();
> ds = (DataSource)initialCtx.lookup("java:/jdbc/UsageLiveDS");
>
> How do I grab a datasource without 'hardcoding' it in this class? In
> other words, how do I dynamically map a datasource using ejb-jar.xml,
> and jboss.xml, and have a stateless bean use this datasource?
>
> Thanks in advance.
>
> David
>
>
>
>
>
>
>
> _________________________________________________________________
> MSN Photos is the easiest way to share and print your photos:
> http://photos.msn.com/support/worldwide.aspx
>
>
> _______________________________________________________________
>
> Don't miss the 2002 Sprint PCS Application Developer's Conference
> August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm
>
> _______________________________________________
> JBoss-user mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/jboss-user
_______________________________________________________________
Don't miss the 2002 Sprint PCS Application Developer's Conference
August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user