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

How to use Hibernate from a HttpServlet

 
Rory Evans
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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
 
Amit ChaudhariC
Ranch Hand
Posts: 33
 
Amit ChaudhariC
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tried it long back but i hope it works - http://www.kodejava.org/examples/32.html

Regards,
Amit
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic