Sunday, January 06, 2008

EJB3, Glassfish, MySQL, Toplink Working Together Continued

Alright, here are my notes on all of this.

First, much of the documentation out there on the web I saw had plenty of JPA for J2SE examples. Nothing I found talked about the setup of the glassfish data pools and sources.

<jta-data-source>jdbc/MySQL</jta-data-source>


Shows the configuration for the persistence.xml you'll need to include. This should be part of the <persistence-unit> tag that you'll include as part of persistence.xml. EJB3 users should know how to set this up or can easily reference this.



That's about the only real configuration you'll need as part of your persistence.xml file for the Glassfish server to locate your connection.



The rest is in glassfish. Why the Apress EJB3 book does include this information is beyond me. It's like a whole chapter on setting up the data sources is needed.



In glassfish login and go to your connection pools for JDBC



From here you'll need to create a new connection pool. Configure the connection as a javax.sql.DataSource then use the Database Vendor MySQL. You'll also need to give it a name. Save your new connection pool, then go back into it to make the following modifications under "Additional Properties" tab.

Under the advanced properties tab, you'll need to create a 'user' property and give it the user name. This would be whatever the mysql login is. Since I was using my research server I simply used 'root'. I didn't have to specify a 'password' property, but I imagine you'll need to in an actual configuration on a live server.

From there you'll need to modify the URL properties (I noticed there were 2 different ones, so I modified both to match). This should be something like 'jdbc:mysql://localhost/XE' where XE is the database you're attempting to access.

Now go back into the JDBC settings and go to JDBC resources. This is where you want to give it a name which matches the jta tag above. create a new JDBC resource that points to the connection pool you just created.

I found it necessary to restart Glassfish here. Although not every change here requires a glassfish restart technically. In practice I couldn't get it to work without the restart.

That was it, once that is setup you should be able to have your client access the localhost for the proper database connection which is mysql and not derby.

2 comments:

Chuck said...

Thank you for the describing what you did! It was the last piece I needed for getting all the same pieces to work together. I find it strange that so much fiddling is necessary to get MySQL working with GlassFish, and it was frustrating hunting around the web for the info.

Anonymous said...

Yes, just what Chuck said!