Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

struts with hibernate.

 
sure nandu
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai everybody,


iam a bit new to hibernates. so i did a simple application using hibernates in struts framework. i had not mentioned any plugin in struts-config.xml. but the application was working fine. iam very confused that how did the struts came to know about the location of
my hibernate.cfg.xml and mapping.hbm.xml. but both files was set in my classpath. if anybody knows the answer please inform.
thanks in advance.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As long as these files are in your classpath, Hibernate can find them.

The important thing to remember when using Hibernate in a web application is that creating the session factory is an expensive and resource intensive task, so you want to make sure you only perform it once and then create a reference to the session factory that you can retrieve somewhere.

One common approach when using Struts is to create a plugin and register it in the struts-config.xml file. This plugin then instatiates the session factory and puts it in Application scope so that it can be retrieved when it's needed.

Another approach is to create a singleton that stores the session factory as a static variable. Either way works.
 
sure nandu
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks merill for yor detailed reply.

i will try to search a plugin.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!