*
The moose likes JBoss/WildFly and the fly likes Lookup a MySQL Datasource with a EntityBean EJB with jboss Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "Lookup a MySQL Datasource with a EntityBean EJB with jboss" Watch "Lookup a MySQL Datasource with a EntityBean EJB with jboss" New topic
Author

Lookup a MySQL Datasource with a EntityBean EJB with jboss

antoine onnen
Greenhorn

Joined: Nov 18, 2003
Posts: 1
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
 
 
subject: Lookup a MySQL Datasource with a EntityBean EJB with jboss
 
Similar Threads
How to get the datasource from Bean through deployment descriptor
error in deploying ejb2.0 bmp in jboss 4.5
error in deploying ejb2.0 bmp in jboss4.5
DeploymentException: Error cant find datasource:
InitialContext for EJB 2.x JNDI on Glassfish v2ur2 under Windows Vista