- Apache Tomcat {5.5.17}
- SpringFramework {1.2.8}
- Hibernate ORM {3.0}
- MySQL {5.0}
First Issue
When integrating the Spring Framework and the Hibernate ORM, my Tomcat server complained during start up that it could no find the Hibernate hbm.xml files. I attempted to use Spring's HibernateTemplate for the integration. When registering the LocalSessionFactoryBean into the Spring XML configuration files, I listed the Hibernate hbm.xml files as the "mappingResources" parameter, along with other parameters. Here is the error message that is spit out by the Tomcat server:
Caused by:
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/jnfintl-data.xml]:
Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError
Caused by:
java.lang.NoClassDefFoundError
at org.hibernate.tuple.EntityMetamodel.class$(EntityMetamodel.java:41)
at org.hibernate.tuple.EntityMetamodel.(EntityMetamodel.java:122)
....
As some suggested, this error may occurr because the container cannot find the hbm.xml files in its classpath, and therefore they suggest to add "classpath:/package.java.class" into the Spring XML configuration file. I tried this approach, but it did not solve my problem. After further investigation, I realized that there I miss one jar file on my web application that caused this issue, the cglib-2.1.3.jar. After putting back the jar file into the application lib folder, I did not see the error message anymore when I started up my Tomcat server, and the web application works just fine now.
Second Issue
When using Spring WebMVC to map a URL request that contains a directory structure, the framework failed to map the relevant physical directory, causing the browser to displays HTTP 404 error msg reporting that the requested resource is not available. I attempted to use a combination of UrlFileNameViewController and SimpleUrlHandlerMapping in my Spring XML configuration file to map a URL request with its corresponding JSP file. However, the UrlFilenameViewController failed to find and display the JSP files that are organized within a directory structure. For example:
...
<bean id="urlFilenameViewController" class="org.springframework.web.servlet.mvc.UrlFilenameViewController"/>
<bean id="simpleUrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/test/testDbConnectionPool.html">
urlFilenameViewController
</prop>
</props>
</property>
</bean>
...
When the browser requested http://localhost:8080/somewebapp/test/testDbConnectionPool.html, the server complained that it could not find the requested resources.
This turned out to be a bug (or an enhancement?) within the version of Spring Framework that I was using. After updating the Spring Framework jar files with the version 2.0 M5 development release, the isssue is solved.
Third Issue
I kept encountering the Lazy Initialization error when trying to access an associated/joined objects from another object that is returned by the hibernateTemplate's load method. I think this was due to my lack of understanding of Hibernate lazy initialization concept. It is a new concept that is introduced in Hibernate 3.0.
I found Mr. Baum's blog that discussed the problem and provided alternative solutions to my problem. Please visit Mr. Baum's discussion about the ORM Lazy Initialization With DAO to read more about it. It's very well written and easy to understand. I tried Mr. Baum suggestion, and it worked very well with my case. The only catch that I encountered was caused by a Spring Framework's hibernate template version difference. The sample codes provided by Mr. Baum is using the older version of the Spring Framework. If you are using the newer framework, make sure that you are using the hibernate3 template.
While investigating on my problems on the Internet, I also stumbled into a good article about Spring Controller, written by Mr. Mike Raible. You can find this article at Mr. Raible's Wiki: SpringControllers.
2 comments:
Thank you, dude.
Your article saved me a lot of time and health.
Be cool!!!
glad that it can help you with ur problem.
Post a Comment