Announcement Announcement Module
Collapse
No announcement yet.
how to use hibernate sessionfactory in startup servlet Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to use hibernate sessionfactory in startup servlet

    I would want to use Spring with hibernate caching in my application. My goal is to use hibernate to load my objects upon server startup thru a startup servlet I configured in web.xml.

    Can I use the DAO and SessionFactory that I have configured in the applicationContext.xml in my servlet? Pls provide samples or other ways to implement.

  • #2
    So you want to load your entire database into memory when you start your application? Interesting. You can use the lifecycle interfaces to be notified when the bean is created.
    http://www.springframework.org/docs/...itializingbean
    Last edited by karldmoore; Aug 29th, 2007, 10:14 AM.

    Comment


    • #3
      Well, not really. I just want to load some constant data that will be used thru out the application. I plan to use hibernate's caching facility for this.

      I guess my question is, how can I make use of the sessionFactory and dao (defined as a bean in applicationContext.xml) in the servlet that I will call. I suppose there are classes that I can use just dont know what and how its used. help anyone?

      Comment


      • #4
        Hi,

        Calling DAO direct in the servlet is not a good approach. My suggestion is to put DAO access in ur service call and give that class ref to ur servlet or controller.

        No comes to ur point. Implement ur service call with "InitializingBean" interface. and get the cache values from database in "afterPropertiesSet" method of ur service and put in a hashmap or whatever u want. Now in servlet u can access service and his hashmap(loaded by cahce data).

        Regards,
        Shahzad

        Comment


        • #5
          Originally posted by shahzad.ahsan View Post
          No comes to ur point. Implement ur service call with "InitializingBean" interface. and get the cache values from database in "afterPropertiesSet" method of ur service and put in a hashmap or whatever u want. Now in servlet u can access service and his hashmap(loaded by cahce data).
          I would agree with this approach in principle, it's what I was thinking of.
          Last edited by karldmoore; Aug 29th, 2007, 10:14 AM.

          Comment


          • #6
            Got it. Thanks guys.

            Comment


            • #7
              Not a problem, if you have any more questions about this approach feel free to post back.
              Last edited by karldmoore; Aug 29th, 2007, 10:13 AM.

              Comment

              Working...
              X