• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to use Hibernate from a HttpServlet

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I currently have a project that is configured to use Spring and Hibernate (I let Spring take care of setting up Hibernate). I am successfully using Spring injected beans throughout my application and have also tested to make sure Hibernate is set up correctly.

I have created a servlet that checks incoming requests for request parameters and does a database search based on them. I would like to use Hibernate to do this but am not sure how to use it from my servlet. Can anyone provide an example/suggestions?

I also have a Spring managed DAO which I'm using for all my persistence handling. Preferrably, from my servlet I'd call find() on my DAO. So I guess my question is more 'how do I Spring inject Spring managed beans onto my servlet'?

My servlet currently looks like this:



Thanks
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please check http://docs.jboss.org/hibernate/stable/core/reference/en/html/tutorial.html#tutorial-webapp

Regards,
Amit
 
Amit ChaudhariC
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tried it long back but i hope it works - http://www.kodejava.org/examples/32.html

Regards,
Amit
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where you're using Hibernate from isn't really relevant--moving to the Hibernate forum if the question is actually about Hibernate.

What specifically is the question? So far your code reminds me of this:

But here the miracle is the Hibernate code.
 
Rory Evans
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the links Amit.

I think I'll give the example in your second post a go. Although I'm planning on using the @Autowired annotation to wire in my UserDAO - this should save me having to manually get the Spring Context.

Apologies for marking this as a Hibernate question - upon further inspection it's more to do with injecting Spring managed beans into a servlet.

Thanks
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic