aspose file tools*
The moose likes JBoss/WildFly and the fly likes Connecting to MySQL 5 in JBoss 5 AS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "Connecting to MySQL 5 in JBoss 5 AS" Watch "Connecting to MySQL 5 in JBoss 5 AS" New topic
Author

Connecting to MySQL 5 in JBoss 5 AS

Daniel Jabonete
Ranch Hand

Joined: Apr 01, 2007
Posts: 78
Greetings!

I am running into a confusion in JBoss AS (ver. 5) �standardjbosscmp-jdbc.xml� under conf folder, which have the following:

<jbosscmp-jdbc>
<defaults>
<datasource>java:/DefaultDS</datasource -->
<!-- optional since 4.0 <datasource-mapping>Hypersonic SQL</datasource-mapping> -->

My question would be �can we have a multiple data source?� like below:

<jbosscmp-jdbc>
<defaults>
<datasource>java:/MySqlDS</datasource>
<datasource>java:/DefaultDS</datasource>

Or maybe the question is �can JBoss AS 5 handle connection in multiple databases?�

Some of the article I�ve seen that were pointing to �how to replace the default data source connection which is Hypersonic SQL DB�.

Thanks in advance for your help, I really appreciate it!

Cheers!

Daniel
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10266
    
168

Why do you want to have multiple "default" datasources?


[My Blog] [JavaRanch Journal]
Daniel Jabonete
Ranch Hand

Joined: Apr 01, 2007
Posts: 78
Hi,

This is most likely manipulate different database in my program. As we can specifically say:

@Resource(mappedName="java:/DefaultDS") DataSource dataSource;

in which DefaultDS points to the Hypersonic SQL DB.

I've just thought that programmatically we can call more than one Datasource:

@Resource(mappedName="java:/MySqlDS") DataSource dataSource;
@Resource(mappedName="java:/DefaultDS") DataSource dataSource;

Regards,

Daniel
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10266
    
168

So you are trying to create a datasource to be used in your application. You don't have to change the existing default datasource. All you have to do is create a file named *-ds.xml and place it in the deploy folder of JBoss. The contents of the -ds.xml are explained here
Daniel Jabonete
Ranch Hand

Joined: Apr 01, 2007
Posts: 78
Hi Jaikiran,

Thanks for the response!

I�m currently doing an EJB 3.0 app and I would like to use MySQL 5.x instead of the default HSQL of JBoss.

Some of the issues that I am having difficulties would be the ff:

1) right or best (production grade) set-up for JBoss AS 5 & MySQL 5.x.
2) using JPA and EJB 3.0.

I� am having some problems/errors when testing the deployed jar, particularly in the InitialContext part.

3) the right configurations in my file, like in my persistence.xml, and others.

I am not sure if there are some easy way of steps in doing these stuff. I�ve searched some articles but it seems I am still lost.

I�ve really appreciate some help with these. Thanks in advance!

Kind regards,

Daniel
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10266
    
168

Originally posted by Daniel Jabonete:
I�m currently doing an EJB 3.0 app and I would like to use MySQL 5.x instead of the default HSQL of JBoss.

That's possible.

Originally posted by Daniel Jabonete:
1) right or best (production grade) set-up for JBoss AS 5 & MySQL 5.x.

You can use JBoss-5.0 GA and any latest stable version of MySQL database server and driver. Follow Peter's advice here. All you have to do is create a -ds.xml file and drop it in the deploy folder of JBoss. You can find a sample mysql-ds.xml in %JBOSS_HOME%/docs/examples/jca folder. Also, drop the MySQL JDBC jar file in %JBOSS_HOME%/server/default/lib folder.

Originally posted by Daniel Jabonete:
2) using JPA and EJB 3.0.

Is this the first time, you are trying to use EJB3 and JPA? Just trying to understand whether you are having any JBoss specific issues or any generic EJB3 issues

Originally posted by Daniel Jabonete:
I� am having some problems/errors when testing the deployed jar, particularly in the InitialContext part.


Please post more details including stacktrace and relevant code. We will be glad to help.

Originally posted by Daniel Jabonete:
3) the right configurations in my file, like in my persistence.xml, and others.


Does this help?
[ January 03, 2009: Message edited by: Jaikiran Pai ]
Daniel Jabonete
Ranch Hand

Joined: Apr 01, 2007
Posts: 78
Hi Jaikiran,

I've read the EJB 3.0 from O'Reilly and successfully run the sample source codes included in there using JBoss

4.2.2.

And now I've this new and would like to try it out using JBoss AS 5 & MySQL 5.

I've successfully compiled & deployed my *.jar file in JBoss 5:



I'm having some problem testing it. This is my standalone client class for testing:



and this is my persistence.xml below:



when I tried to run the client class for testing, it returns some stackTrace error:



I am trying to have a separate project in eclipse 3.2 for testing the deployed Entities & Session Beans.

Thanks in advance for your help, really appreciate it!

Kind regards,

Daniel
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10266
    
168

[java] java.io.NotSerializableException: es.com.domain.Employee.Employee


Your es.com.domain.Employee.Employee entity and other entities should implement the java.io.Serializable interface.
Daniel Jabonete
Ranch Hand

Joined: Apr 01, 2007
Posts: 78
Hi Jaikiran,

I've also tried that, serializing my entities, and same result I've received for my separate test project in eclipse.

But when I've checked where the compiled class goes & my build.xml in ant, it seems that there are some problems in the placement of the build class.

I'd clean it up, then make sure that I am referring to the right class, as well as the *.jar files for the client. And it works with flying colors!

Now, I would like to test this in a web app. Any advice for doing this...

Thanks again for your help, really appreciate it!

Cheers!

Daniel
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10266
    
168

Daniel Jabonete wrote:
Now, I would like to test this in a web app. Any advice for doing this...



You can create a WAR containing the web application and then create an EAR with this WAR and the EJB jar. The bean lookup code will remain the same, but will be moved out from the standalone client to some servlet (just an example), in the web application.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Connecting to MySQL 5 in JBoss 5 AS