Wednesday, 19 August 2015

Exception in thread "main" java.lang.ExceptionInInitializerError at Test.Test.main(Test.java:20) Caused by: org.hibernate.HibernateException: /hibernate.cfg.xml not found

such type of exception may occur in hibernate when the configuration file - hibernate.cfg.xml can not be located by the hibernate system while developing project in Eclipse IDE. it is because if you have not given the path for the hibernate.cfg.xml file properly ..
if in your eclipse project if you are keeping your files in different packages then make sure you gave the path of the packages..
to solve the above problem you need to follow the below steps
Procedure number 1:
1)you need the give the path of the package in your mapping file(say here employee.hbm.xml)  for the name attribute of  <class name="<here>"  >  tag ..

2)and also you need to provide the full package path in the  <mapping resource="<here> "> tag of the hibernate.cfg.xml file

again while creating the Configuration  Object also you need to provide the full package name in the configure(< here> ) method

so by above process you make your hibernate system know from where to locate the hibernate.cfg.xml file

Procedure number 2

instead of procedure number 1 you can simply place you configuration file and mapping file inside the classes folder of WEB-INF 
simply copy and paste the hibernate.cfg.xml and hbm.xml(here employee.hbm.xml inside the classes folder of WEB-INF folder


0 comments:

Post a Comment