Hi,
Step 1. You should have a getConnection() method
that returns a java.sql.Connection object, which is retrieved through
Context.lookup(). We use a base class with the following method:
protected Connection getConnection()
throws SQLException {
Connection conn = null;
Object o;
Connection conn = null;
Object o;
String url =
"java:comp/env/jdbc/MyDB";
if (ds == null) {
try {
o = ctx.lookup(url);
ds = (javax.sql.DataSource) o;
} catch (NamingException e) {
throw new SQLException("Cannot find "+url+"\n"+e.getMessage());
}
}
return ds.getConnection();
}
if (ds == null) {
try {
o = ctx.lookup(url);
ds = (javax.sql.DataSource) o;
} catch (NamingException e) {
throw new SQLException("Cannot find "+url+"\n"+e.getMessage());
}
}
return ds.getConnection();
}
Your ejb-jar.xml should look like
this:
<entity>
<ejb-name>MyBean</ejb-name>
<home>MyBeanHome</home>
<remote>MyBean</remote>
<ejb-class>MyBean</ejb-class>
<persistence-type>Bean</persistence-type>
<prim-key-class>java.lang.String</prim-key-class>
<reentrant>False</reentrant>
<resource-ref>
<res-ref-name>jdbc/MyDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</entity>
<ejb-name>MyBean</ejb-name>
<home>MyBeanHome</home>
<remote>MyBean</remote>
<ejb-class>MyBean</ejb-class>
<persistence-type>Bean</persistence-type>
<prim-key-class>java.lang.String</prim-key-class>
<reentrant>False</reentrant>
<resource-ref>
<res-ref-name>jdbc/MyDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</entity>
The url used in getConnection() refes to the
res-ref-name entry in your ejb-jar.xml
The res-ref-name is then further used in your
jboss.xml
<resource-managers>
<resource-manager res-class="org.jboss.ejb.deployment.JDBCResource">
<res-name>jdbc/access</res-name>
<res-jndi-name>java:/MyDB</res-jndi-name>
</resource-manager>
</resource-managers>
<resource-manager res-class="org.jboss.ejb.deployment.JDBCResource">
<res-name>jdbc/access</res-name>
<res-jndi-name>java:/MyDB</res-jndi-name>
</resource-manager>
</resource-managers>
<enterprise-beans>
<entity>
<ejb-name>MyBean</ejb-name>
<jndi-name>my/MyBeanHome</jndi-name>
<configuration-name></configuration-name>
<resource-ref>
<res-ref-name>jdbc/MyDB</res-ref-name>
<resource-name>jdbc/access</resource-name>
</resource-ref>
</entity>
<ejb-name>MyBean</ejb-name>
<jndi-name>my/MyBeanHome</jndi-name>
<configuration-name></configuration-name>
<resource-ref>
<res-ref-name>jdbc/MyDB</res-ref-name>
<resource-name>jdbc/access</resource-name>
</resource-ref>
</entity>
</enterprise-beans>
Eventually, we end up with the res-jndi-name in
jboss.xml referring to the connection pool name specified in
jboss.jcml
<mbean
code="org.jboss.jdbc.XADataSourceLoader"
name="DefaultDomain:service=XADataSource,name=MyDB">
<attribute name="PoolName">MyDB</attribute>
<attribute name="DataSourceClass">org.opentools.minerva.jdbc.xa.wrapper.XADataSourceImpl</attribute>
<attribute name="Properties">URL=jdbc:oracle:thin:servsoft/servsoft@pluto:1521:servsoft</attribute>
<attribute name="URL">jdbc:oracle:thin:@pluto:1521:servsoft</attribute>
<attribute name="JDBCUser">user</attribute>
<attribute name="Password">pwd</attribute>
</mbean>
<attribute name="PoolName">MyDB</attribute>
<attribute name="DataSourceClass">org.opentools.minerva.jdbc.xa.wrapper.XADataSourceImpl</attribute>
<attribute name="Properties">URL=jdbc:oracle:thin:servsoft/servsoft@pluto:1521:servsoft</attribute>
<attribute name="URL">jdbc:oracle:thin:@pluto:1521:servsoft</attribute>
<attribute name="JDBCUser">user</attribute>
<attribute name="Password">pwd</attribute>
</mbean>
Hope this helps. Let me know if you need
more.
Regs,
Ijonas.
----- Original Message -----
From: "Cokorda Raka Angga Jananuraga" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, April 19, 2001 3:38 PM
Subject: Re: [JBoss-user] DataSource, JDBC, and
stuffs
>
> I have exactly the same problem (please see email with
> subject: JNDI and Connection Pool, etc. From
> Pellegrini, John. Posted on Sun, 01 Apr 2001 06:49:56
> -0700).
>
> Please, does anybody know the answer to this problem.
>
> thanks a lot,
> Raka
>
> --- Cokorda Raka Angga Jananuraga
> <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > I'm a newbie to EJB and JBoss.
> > Now, I'm entering creating BMP entity bean chapter
> > in
> > my EJB book.
> >
> > I have trouble in deploying the bean, especially
> > mapping a jndi name to a connection pool (?).
> >
> > Which files to configure, and how ? I can't find
> > enough clues in JBoss documentation.
> >
> > I've searched the maillist archive, but found little
> > reference.
> >
> > Any hints would be very appriciated.
> >
> > Thanks a lot,
> > Raka
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Yahoo! Auctions - buy the things you want at great
> > prices
> > http://auctions.yahoo.com/
> >
> > _______________________________________________
> > JBoss-user mailing list
> > [EMAIL PROTECTED]
> >
> http://lists.sourceforge.net/lists/listinfo/jboss-user
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Auctions - buy the things you want at great prices
> http://auctions.yahoo.com/
>
> _______________________________________________
> JBoss-user mailing list
> [EMAIL PROTECTED]
> http://lists.sourceforge.net/lists/listinfo/jboss-user
>
