This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
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

Hibernate configuration class

 
Frank Serkland
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had a response to a problem I posed on the Struts forum, and that response raised questions in my mind that are more appropriate for this forum, since they concern Hibernate. The response involved Hibernate configuration and creating a single instance of SessionFactory. After reading a textbook I have and doing several Google searches, it seems that it's best to perform these in a separate class that runs before anything else in the web application. Here's what I don't understand.

1. How does this class actually get called?

2. Where in the file structure of the web application is this class stored?
 
Paul Clapham
Sheriff
Posts: 21572
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a ServletContextListener.

It gets called (or more accurately, certain methods of it get called) when the container starts the web application and when the container ends the web application. (Naturally it's the container which calls those methods.)

It goes in the same place as your servlets. There's some configuration for it in the web.xml file.

(You'll notice this has nothing to do with Hibernate; you can do anything that needs to be done at app startup and shutdown in this class. You just never know where questions are going to lead, do you?)
 
Frank Serkland
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, thank you, Paul. This is the information I needed. I think I can proceed from here.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic