• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Using getHibernateTemplate() problem

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi,

I'm a newbie to Spring. May be this question sound a childish, but still i need some help in this problem.

In a DAO which extends HibernateDaoSupport, i have a method named findByProperty in which i call

getHibernateTemplate().find(queryStr, value);

The problem is i get a nullPointerException for getHibernateTemplate() method.
I have defined a sessionFactory in application-context.xml. Also the DAO has a reference to the sessionFactory bean through sessionFactory property in the application-context.xml file.

Wt can be the problem or do i miss anythg???

I need some guidence in this problem.

thanks in advance.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd recommend posting at least the relevant Spring config (and always UseRealWords, which you mostly did until the very end ;)
 
Prasath Premkumar
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi david,

I'm sorry about typing short words, here after i'll stick to your advice. Sorry again.

Here is the relevent part of my application-context.xml file:



Here is the part of my Hibernate.cfg.xml which maps to the Users table for which UsersDAO is written



In acheivers-servlet.xml (dispatcher servlet) i have defined this :


In the login controller i'm using the UsersDAO like this:



In the UsersDAO the above called method is defined like this:


But i get a nullPointer on getHibernateTemplate() method. Why is that?? do i miss anythg???

I read that HibernateDAOSupport can create a HibernateTemplate if sessonFactory is specified. I have defined sessionFactory in application-context.xml. Is that all i need to do??

Please guide me and give an explanation. Sample codes will be much more helpful.

Thanks a lot.
 
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where is your dataSource? Add it to your sessionFactory as a property:
 
Prasath Premkumar
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi,

Thanks for the suggestion, i tried it but still it is throwing a nullPointerException for getHibernateTemplate() method.

Anyway, the database is defined in hibernate.cfg.xml and passed to the sessionFactory bean as a property, so do i need to set the dataSource property again???

I'm confused with why getHibernateTemplate() throwing a NullPointerException..... The sessionFactory is defined in application-context.xml, so the sessionFactory is set, isnt it? Or are there any sessionFactory bean injection to be done in order to get the HibernateTemplate???

Thanks.
 
Eduardo Bueno
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nevermind what I said, haven't seen the dataSource properties configured in your hibernate-config. I have no idea why hibernateTemplate is null; have you tried not to use it? By the way, it's use is discouraged.
 
Yes, of course, and I accept that blame. In fact, i covet that blame. As does this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic