Win a copy of Emmy in the Key of Code this week in the General Computing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

getHibernateTemplate redux

Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this older post is related:

I'm just trying to test simple CRUD using Spring,Hibernate,Tomcat,MySQL - without any success so far.

Classes that extend HibernateDAOSupport have NPEs on calls such as:
and this.getSesssionFactory is always null.

On app/tomcat start-up, the datasource (through JNDI) is being found as far as I can tell:
INFO: RDBMS: MySQL, version: 5.0.18-nt
Apr 9, 2006 3:43:11 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.12

in my applicationContext.xml:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">

bean config for class extending HibernateDAOSupport:
<bean name="schoolAdminMgr"
<property name="sessionFactory">
<ref local="sessionFactory"/>

bean config for sessionFactory:
<bean id="sessionFactory"
<property name="dataSource"><ref local="dataSource"/></property>
<property name="mappingResources">
...hbm xml files...
<property name="hibernateProperties">
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>

I'm creating a context.xml to be included in META-INF under the web-app in Tomcat. It looks like this:
<Context reloadable="true" path="amadeus" docBase="amadeus">

<Resource type="javax.sql.DataSource"


mysql driver, commons-dbcp jars copied to tomcat's common/lib folder.

The only symptom I'm seeing is the NPE and null sessionFactory in the running web-app.

I don't know where to focus my attention now on troubleshooting this, any suggestions are much appreciated. I suspect it's probably still something with Tomcat and the datasource...but have exhausted all ideas to try.
bob daly
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have figured out my problem (to some extent, anyway).
All I wanted to see were signs of life to do CRUD against the db.

From within an action class of the web-app (using WebWork framework), this works - but is ugly and need to create a true facade/service layer that provides access to the DAO layer...

> XmlWebApplicationContext appContext =
> (XmlWebApplicationContext)WebApplicationContextUtils.getWebApplicationContext(ServletActionContext.getServletContext());
> appContext.refresh();
> PojoTestMgr mgr = null;
> try {
> //pojoTestMgr is id of bean in applicationContext.xml
> //it's a dao class that extends HibDaoSupport
> mgr = (PojoTestMgr)appContext.getBean("pojoTestMgr");
> }
> catch(Exception e) {
> e.printStackTrace();
> }
I didn't like the taste of tongue and it didn't like the taste of me. I will now try this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!