my dog learned polymorphism
The moose likes Struts and the fly likes struts with hibernate. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts with hibernate." Watch "struts with hibernate." New topic

struts with hibernate.

sure nandu

Joined: Oct 16, 2006
Posts: 18
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

Joined: Feb 15, 2005
Posts: 4864
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.

Consultant, Sima Solutions
sure nandu

Joined: Oct 16, 2006
Posts: 18
thanks merill for yor detailed reply.

i will try to search a plugin.
I agree. Here's the link:
subject: struts with hibernate.
It's not a secret anymore!