Results 1 to 7 of 7

Thread: how to use hibernate sessionfactory in startup servlet

  1. #1
    Join Date
    Jul 2007
    Posts
    11

    Default 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. #2
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    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 at 10:14 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  3. #3
    Join Date
    Jul 2007
    Posts
    11

    Default

    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?

  4. #4

    Smile

    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

  5. #5
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Quote 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 at 10:14 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  6. #6
    Join Date
    Jul 2007
    Posts
    11

    Default

    Got it. Thanks guys.

  7. #7
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Not a problem, if you have any more questions about this approach feel free to post back.
    Last edited by karldmoore; Aug 29th, 2007 at 10:13 AM.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •