AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Lookup a MySQL Datasource with a EntityBean EJB with jboss

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases
View previous topic :: View next topic  
Author Message
Antoine Onnen
Guest





PostPosted: Mon Nov 17, 2003 11:24 pm    Post subject: Lookup a MySQL Datasource with a EntityBean EJB with jboss Reply with quote



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






Back to top
Antoine Onnen
Guest





PostPosted: Wed Nov 19, 2003 11:59 pm    Post subject: Re: Lookup a MySQL Datasource with a EntityBean EJB with jbo Reply with quote



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

"Antoine Onnen" <antoine.onnen (AT) noos (DOT) fr> wrote

Quote:
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 /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









Back to top
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java and Databases All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.