Win a copy of Event Streams in Action this week in the Java in General 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

NullPointerException while initializing org.springframework.orm.hibernate4.LocalSessionFactoryBean

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hibernate-cfg.xml:


Error while starting tomcat:


Please help to solve the issue.

Thanks in advance.
 
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are specifying mapping resources using <mappingResources> tag, don't prefix with "classpath:".
Items in <mappingResources> are passed as they are to Hibernate without Spring pre-processing the "classpath:" prefixes, and Hibernate doesn't understand what to do with the "classpath:" prefixes. Hence your error.

A better option is to use <mappingLocations> instead of <mappingResources>, because you can specify "classpath:" in them. It's a subtle difference.

PS: Welcome to CodeRanch ! Please change your username to a real name as per our naming policy http://www.javaranch.com/name.jsp.
 
Ganesan Shankar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Karthik for your quick rely.
Below are the approaches I tried, but getting the same error in all the attempts




Source Structure:
Java Resources
--src
----config.db
--------database.properties
--------hibernate-cfg.xml
----config.db.mapping
--------userdetails.hbm.xml
WebContent

userdetails.hbm.xml:
=============


Product.java:
========
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the filenames. Resources say "userdetails.hbm.xml" but the file structure says it's "userdetails.xml".
 
Ganesan Shankar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have corrected the typo error in my previous post (it is userdetails.hbm.xml)
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried to reproduce your problem in a Eclipse dynamic web project - copy pasted all your configuration files, created matching package structure, added Spring 4.1 and hibernate 5.1.0 libs.
It's all working fine for me. I don't think there is anything wrong with your configuration files now.

Googling some parts of the exception traces leads to this discussion where somebody has got the same exception as you.
Apparently, one possible cause is if Hibernate and/or Spring are added to the Eclipse build path as a "User library" with "System library" checkbox checked.
Have you added them as a "User Library" or something? In my case, I just copied all the JARs into WebContent/lib and refreshed the project. Maybe you can remove any User Libraries you have added and try this approach.
 
Ganesan Shankar
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. It works after moving all the jars to WEB-INF/lib.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!