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 ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

getHibernateTemplate redux

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this older post is related:
https://coderanch.com/t/60068/oa/NPE-at-getHibernateTemplate

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:
getHibernateTemplate().save(pojoObj)
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">
<value>java:/comp/env/jdbc/amadeus</value>
</property>
</bean>

bean config for class extending HibernateDAOSupport:
<bean name="schoolAdminMgr"
class="com.overture.amadeus.service.HibSchoolAdminMgr">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>

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

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"
auth="Container"
name="jdbc/amadeus"
factory="org.apache.commons.dbcp.BasicDataSourceFactory"
initialSizse="30"
maxActive="100"
maxIdle="30"
maxWait="10000"
username="root"
password="root"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/amadeus?autoReconnect=true"
removeAbandoned="true"
removeAbandonedTimeout="60"
logAbandoned="true"
/>

</Context>

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
Greenhorn
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)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!