Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem while running Junit test in hibernet

 
Sanjay Chougule
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

I am new to Hibernate , & i am facing the problem while running JUnit test .... i am getting this error ..

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.

org.hibernate.HibernateException: /hibernate.cfg.xml not found

i am successfully running jsp with "hibernate.cfg.xml" ....is there any problem with my hibernet.hbm file ...?

thanks in advance .
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have two problems, the first one not that serious:

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.

You have not initialised log4j properly. In the long run its probably a good idea to fix this, otherwise you will not get any logging from your unit tests.

The other probolem:

org.hibernate.HibernateException: /hibernate.cfg.xml not found

Assuming you are using the default way to initialise the SessionFactory, Hibernate's Configuration class will look for hibernate.cfg.xml at the root of the classpath. Have you deployed it there?
 
Sanjay Chougule
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks poul ,
i have written "AbstractHibernateHandler.java " for working with sessionFactory , & i really didn't get what do you mean by deploy hibernate.cfg.xml file....
could you please explain me ....
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where do you run your tests? Presumably you are not running code in WEB-INF/classes, as you would in your web application. So you will (I'm assuming) have a directory where you compile all your all your java files to? Hibernate.cfg.xml needs to be at the root of this directory structure.
 
Sanjay Chougule
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have a directory structure like this...
in folder
---------------------------------------------------------------------------
Myproject->
src--->com.abc.util
com.abc.model
com.abc.handler
xyz--->jsp
js etc.
Resource-----> contain all " .hbm.xml" & "hibernate.cfg.xml" files
---------------------------------------------------------------------------

i have written my test cases in handler package... i run these handler test
as "run as Junit test ."
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you configure your SessionFactory without specifying where the hibernate configuration file is, then Hibernate looks for it in the root folder where your classes are. So wherever you compile your source to, that is where the configuration file needs to be. It sounds like you are using an IDE; typically an IDE will just compile stuff to a defined directory and copy over any other files it finds in the source tree there too. So, you need to put your hibernate.cfg.xml file at the root of your src folder.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic