• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I work around this MySQL/JPA in WebApp bug?

 
Stephen Gaukrodger
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get the following error when I try to persist something from a servlet I just wrote:

java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/webbookingError Code: 0

It happens at a line where I try to create an EntityManager.

I found the following bug report:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6543396

But I don't really understand the answer.
Marina from the persistence team and I put our heads together and we think we understand what's happening and we have some ideas for the fix. I'll describe what happens in the appclient script case. The Java Web Start case is similar and will require a fix or two in that code as well but it's basically the same issue.Briefly, it's related to classloading. TopLink Essentials is the code searching for the driver, and TLE is loaded by the system class loader by virtue of the CLASSPATH environment variable as set in the appclient script. The Derby client JAR also appears in that CLASSPATH variable, so when TLE searches for the Derby driver it can find it because both JARs are in the classpath for the same classloader. This is because java.sql.DriverManager uses the class loader that loaded the calling class to search for the driver class.JARs packaged inside your app client or EAR are loaded by a different classloader, one created by the app client container and that knows about the contents of the generated app client JAR. This classloader's parent is the system class loader. When TLE tries to find an alternate driver that has been packaged in the EAR, it cannot because the system class loader - the one that loaded TLE - does not know about the alternate drier JAR. I sketched out some ideas for how to address this to Marina and she agrees theyare worth pursuing. Basically, we'd remove the TopLinkEssentials and derbyclient JARs from the CLASSPATH definition in the script. Instead the ACC would add those JARs to the class path for the child class loader that the ACC creates. That way TLE's class loader would know about the alternate driver JARand so TLE could locate the driver successfully. It will take a little time because I will be out of the office all next week and won't be able to work on this. Also Marina noted a potential wrinkle that I think we can handle but we need to be careful, and of course we'll need to testany proposed change very thoroughly. So that's the plan at the moment. Stay tuned.- Tim
Posted Date : 2007-04-23 19:04:48.0


In the next post he confirms that this is the solution. Now what do I do? Do I emulate their solution (if so how?) or do I wait for a patch to whatever is wrong.

I'm using netbeans to set up the webapplication, the toplinkessentials library to access the MySQL database, and Prozac to stop my head exploding. I'm happy to supply any more details that might be useful.

Any help much appreciated.
Steve
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the ORM forum. JPA questions are best answered there, since JPA is part of the spec, but can run outside of J2EE, and is more ORM now.

Thanks

Mark
 
Stephen Gaukrodger
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fair. I wasn't sure where to put it.

After tweaking my caffine/prozac balance with some nicotine, I have now found that it works in tomcat (5.5.17), but not with the Java application server. This is very strange.

The nicotine is killing me, but thanks to the prozac I don't care.

Steve
[ May 31, 2007: Message edited by: Stephen Gaukrodger ]
 
Mike Keith
author
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like the bug that you were looking at describes a problem using JPA from app clients directly, not in the server. In the server you should just be able to have the driver jar on your server or app classpath.

-Mike
 
Stephen Gaukrodger
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I thought that was the case, but I wasn't really sure I understood what was being said. I've managed to make it work by adding the path to the JVM on the Application Server, but I don't like that solution - I want to add it to the WAR file on an as needed basis. I'm just picky like that

For now, it works and I'm happy. I'll do some more of this when I get spare time.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic