|
Subject:
|
Pain: A touch-up on Beginning JSP Chapter 23
|
|
Posted By:
|
Swede
|
Post Date:
|
4/20/2008 1:03:59 PM
|
When reading this book, I didn’t want to use the more or less outdated software that was used by the authors at the time of writing. I boldly decided to use later versions of MySQL, Tomcat and Hibernate. Here’s a list of what was used in the book, and the versions that I decided to use:
MySQL MySQL 4.0 -> 5.0 Tomcat 5.0 -> 5.5 Hibernate 2.1 -> 3.2
Of course, one doesn’t deviate from a recommended software setup without a lot of pain. After having spent many frustrating hours of Google searches with equally frustrating trial-and-error attempts, I decided to write down the problems I encountered and the fixes that I found for them in this forum. Perhaps some of you will stumble upon the same problems and have some use for it. What’s interesting with Chapter 23 is of course that this is the first attempt in the book to access a database.
I began by installing and configuring everything according to the instructions in the book. And then it started…
1. Outdated import statements
It began easy enough. You will get a compilation error in HibernateRosterManager.java if you have switched from Hibernate 2 to Hibernate 3. Simply change all import statements beginning with net.sf.hibernate to org.hibernate in order to solve that problem.
2. Exception: Cannot create JDBC driver of class '' for connect URL 'null'"
The next problem I encountered was this: Cannot create JDBC driver of class '' for connect URL 'null'"
First of all I changed the content of ch23.xml in order to support Tomcat 5.5 syntax. I removed <ResourceParams> and included all its elements into the <Resource> entry as you can see below. You should of course change the absolute paths below to wherever you keep your ch23 code.
<?xml version='1.0' encoding='utf-8'?> <Context docBase="P:/Code/Wrox/begjsp/ch23/web" path="/ch23" reloadable="true" workDir="P:/Code/Wrox/begjsp/ch23/work">
<Resource name="jdbc/FootyDB" auth="Container" type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/footydb?autoReconnect=true" username="footy" password="footy"/> </Context>
I followed the instructions in the book and copied this (updated) page to [CATALINA_HOME]\conf\Catalina\localhost.
Now here’s the tricky part: you additionally have to insert a new file called context.xml into web\META-INF with the content below: <?xml version='1.0' encoding='utf-8'?> <Context crossContext="true" debug="5" docBase="P:/Code/Wrox/begjsp/ch23/web" path="/ch23" reloadable="true" workDir="P:/Code/Wrox/begjsp/ch23/work">
<Resource name="jdbc/FootyDB" auth="Container" type="javax.sql.DataSource" username="footy" password="footy" driverClassName="com.mysql.jdbc.Driver" maxWait="5000" url="jdbc:mysql://localhost/footydb?autoReconnect=true" maxActive="4" maxIdle="2"/> </Context>
I found this solution described at http://www.theserverside.com/discussions/thread.tss?thread_id=25459#119215. It was easy to see that I wasn’t the only one experiencing this kind of problem…
3. It works! Well, almost.
And la voilá – it started to work! Well, almost anyway. Now I was able to see the Rounds Management page filled with database content, which meant that I had a valid database connection. But the other pages weren’t working at all.
4. InvalidMappingException
I got an org.hibernate.InvalidMappingException on all three remaining jsp pages. This was easily solved by changing all references to http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd to http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd in all four xxx.hbm.xml files.
5. HibernateException: Dialect class not found
After that I got the following exception: org.hibernate.HibernateException: Dialect class not found: net.sf.hibernate.dialect.MySQLDialect. This was of course caused by the change from Hibernate 2 to Hibernate 3 and was also easily fixed in HibernateRosterManager.java, by changing the line:
props.put("hibernate.dialect", "net.sf.hibernate.dialect.MySQLDialect");
to:
props.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
6. NoClassDefFoundError: org/objectweb/asm/Type
I had previously copied the Hibernate 3 versions of all files listed in required-libraries.txt stored in the WEB-INF\lib folder. In the Hibernate 3 distribution, there is no odmg-3.0.jar so don’t waste any time searching for it. It seemed that this list of files wasn’t enough, as I still got a lot of NoClassDefFoundError exceptions. Consulting the list of required files in the Hibernate 3 distribution, this is the resulting list of files that finally worked for me:
antlr-2.7.6.jar asm.jar asm-attrs.jar cglib-2.1.3.jar commons-collections-2.1.1.jar commons-logging-1.0.4.jar dom4j-1.6.1.jar ehcache-1.2.3.jar hibernate3.jar javassist.jar jstl.jar jta.jar log4j-1.2.11.jar standard.jar xml-apis.jar
|
|