Hi, I'm currently trying to figure out how to deploy my first JSP/Spring/Hibernate project and am completely stumped. The way I've organised it is to create a project with my business logic and data access objects, which is put into a jar file (including config files) in my WEB-INF/lib directory. The JSP file then accesses a bean defined in this jar file, which sets up spring and returns a spring bean that accesses the data.
JSP runs, and loads the bean from the jar file. Spring starts initializing, but fails when it tries to create the hibernate SessionFactory. The stack trace of the root cause exception begins:
java.lang.NullPointerException
org.hibernate.util.ConfigHelper.getResourceAsStrea m(ConfigHelper.java:144)
org.hibernate.cfg.Environment.<clinit>(Environment .java:524)
org.hibernate.cfg.Configuration.reset(Configuratio n.java:168)
org.hibernate.cfg.Configuration.<init>(Configurati on.java:187)
org.hibernate.cfg.Configuration.<init>(Configurati on.java:191)
sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInsta nce(Unknown Source)
sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(Unknown Source)
java.lang.reflect.Constructor.newInstance(Unknown Source)
org.springframework.beans.BeanUtils.instantiateCla ss(BeanUtils.java:85)
Relevant parts of my bean configuration are:
<beans [...]>
<tx:annotation-driven transaction-manager="txManager" />
<bean id="dataSource" [...]>[...]</bean>
<bean
id="sessionFactory" autowire="byName"
class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
<property name="mappingResources"><list>
<value>meridian/experimental/hibernatetest/DayList.hbm.xml</value>
<value>meridian/experimental/hibernatetest/DayListEntry.hbm.xml</value>
<value>meridian/experimental/hibernatetest/DayListTask.hbm.xml</value>
</list></property>
<property name="hibernateProperties"><value>
hibernate.dialect=org.hibernate.dialect.MySQLDiale ct
</value></property>
</bean>
<bean id="txManager" autowire="byName"
class="org.springframework.orm.hibernate3.Hibernat eTransactionManager" />
[...]
</beans>
The configuration works fine when I run it as a unit test from within the 'hibernatetest' project.
The files "meridian/experimental/hibernatetest/*.hbm.xml" are located in the jar file, which is the same jar file the spring configuration file is being loaded from, so is clearly accessible. I've also tried putting them in subdirectories from the web application's directory, from the WEB-INF directory and from the WEB-INF/lib directory, so I can only assume the problem isn't that hibernate is looking for them as files rather than on the classpath.
I'd really appreciate it if someone can tell me what I'm doing wrong here.


Reply With Quote
