Lookup a MySQL Datasource with a EntityBean EJB with jboss

A

Antoine Onnen

Hy all,

For a few days, i have problems to instance a datasource from my Entitybean
EJB
jboss release is 3.2.2 , MySQL 3.23.38
i use mysql-connector-java-3.0.9-stable-bin.jar for jdbc connectivity

Here is the source of my datasource mysql-ds.xml

<datasources>
<local-tx-datasource>
<jndi-name>MySQLmydbDS</jndi-name>
<connection-url>jdbc:mysql://localhost:3306/mydb</connection-url>
<driver-class>org.gjt.mm.mysql.Driver</driver-class>
<user-name>mylogin</user-name>
<password>mypass</password>
</local-tx-datasource>
</datasources>

The datasource is deployed in jboss cause i see the ligne as followed in the
administration console
http://localhost:8080/jmx-console

a.. name=MySQLmydbDS,service=LocalTxCM
a.. name=MySQLmydbDS,service=ManagedConnectionFactory
a.. name=MySQLmydbDS,service=ManagedConnectionPool

My EJB deploy without problems when i put the jar in the deploy directory

Here is the part of the source of my EJB causing Exception

public void setEntityContext(EntityContext context) {
this.context = context;
try {
InitialContext ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup("java:comp/env/jdbc/ClientDB");
/* ----> ERROR */
connexionBD = ds.getConnection();
}
catch (Exception e) {
throw new EJBException("Connexion à la base de données impossible : "
+ e.getMessage());
}
}

Here my ejb-jar.xml

<ejb-jar>
<description>Descripteur de déploiement pour l'EJB client</description>
<display-name>EJB Client</display-name>
<enterprise-beans>
<entity>
<description>EJB Client ( BMP )</description>
<ejb-name>Client</ejb-name>
<home>com.foobar.ejbs.ClientHome</home>
<remote>com.foobar.ejbs.Client</remote>
<ejb-class>com.foobar.ejbs.ClientBean</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/ClientDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</entity>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>Client</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>

And finally the jboss.xml

<jboss>
<enterprise-beans>
<entity>
<ejb-name>Client</ejb-name>
<jndi-name>ejb/Client</jndi-name>
<resource-ref>
<res-ref-name>jdbc/ClientDB</res-ref-name>
<jndi-name>MySQLmydbDS</jndi-name>
</resource-ref>
</entity>
</enterprise-beans>
</jboss>


The error message when i execute my client :

java.rmi.ServerException : RemoteException occured in server Thread; nested
exception is :
java.rmi.ServerException: EJBException:; nested exception is :
javax.ejb.EJBException: Connexion à la base de donnée impossible : Could not
dereference object


Thanks in advance if you've already seen this problem.

Antoine
 
A

Antoine Onnen

I find the solution
Just add the dsn "java:/"

<jboss>
<enterprise-beans>
<entity>
<ejb-name>Client</ejb-name>
<jndi-name>ejb/Client</jndi-name>
<resource-ref>
<res-ref-name>jdbc/ClientDB</res-ref-name>
<jndi-name>java:/MySQLmydbDS</jndi-name> <!--Change is here-->
</resource-ref>
</entity>
</enterprise-beans>
</jboss>

Antoine
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top