This post refers to the following hibernate tutorial:
http://www.myeclipseide.com/documentation/quickstarts/hibernate/
Hello, I believe I followed the HIbernate demo closely, but I had 2 different issues:
1. When I first ran the project, it complained about log4j not being set up propertly. To fix, I needed to create a log4j.xml file within the src folder.
log4j.xml:
<?xml version=”1.0″ encoding=”UTF-8″?><!DOCTYPE log4j:configuration SYSTEM “log4j.dtd” >
<log4j:configuration>
<appender name=”stdout” class=”org.apache.log4j.ConsoleAppender”>
<layout class=”org.apache.log4j.PatternLayout”>
<param name=”ConversionPattern” value=”%d{ABSOLUTE} %5p %c{1}:%L – %m%n”/>
</layout>
</appender>
<root>
<priority value=”debug”></priority>
<appender-ref ref=”stdout”/>
</root>
</log4j:configuration>
The second (stranger) problem is that when I would run the application, I’d get a NullPointerException. I tracked the problem down to the
getSession method of the BaseHibernateDAO class. When it was generated, this method was set to return null with a comment “FIXME: Implement this method”.
Here is the corrected method:
public Session getSession() {
//FIXME: Implement this method
//return null;
return HibernateSessionFactory.getSession();
}
Why was this BaseHibernateDAO class generated in this manner?
It’s working fine now, but what gives?? Did I do something wrong that caused both of these problem to happen? It wasn’t very difficult to track down and fix these issues, but I still think the example should just work without having to make any fixes first.
Other than these issues, it’s a very very good tutorial.