 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Antoine Onnen Guest
|
Posted: Mon Nov 17, 2003 11:24 pm Post subject: Lookup a MySQL Datasource with a EntityBean EJB with jboss |
|
|
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
|
Posted: Wed Nov 19, 2003 11:59 pm Post subject: Re: Lookup a MySQL Datasource with a EntityBean EJB with jbo |
|
|
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 |
|
 |
|
|
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
|
|