You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by dinesh707 <di...@gmail.com> on 2013/02/19 14:32:38 UTC

How to inject hibernate session into my Servlet

I have a HttpServlet inside tapestry project. But I think it is not
recognized as a part of IoC. So when I do an inject it does not work. It
ends up throwing a null pointer exception. Any suggestion about how to
inject the same hibernate session. 

Thank you 



--
View this message in context: http://tapestry.1045711.n5.nabble.com/How-to-inject-hibernate-session-into-my-Servlet-tp5720097.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: How to inject hibernate session into my Servlet

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Tue, 19 Feb 2013 10:32:38 -0300, dinesh707 <di...@gmail.com> wrote:

> I have a HttpServlet inside tapestry project.

Why?

> But I think it is not recognized as a part of IoC.

You're right. Only stuff declared as services in Tapestry IoC are  
recognized by IoC.

> So when I do an inject it does not work. It
> ends up throwing a null pointer exception. Any suggestion about how to
> inject the same hibernate session.

TapestryFilter puts the Registry instance in the  
TapestryFilter.REGISTRY_CONTEXT_NAME attribute of ServletContext. From the  
Registry instance, you can use the getService() methods to get any service  
you want.

-- 
Thiago H. de Paula Figueiredo

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: How to inject hibernate session into my Servlet

Posted by Taha Siddiqi <ta...@gmail.com>.
Hi

You have two options.

1. Convert your servlet into a tapestry page. HttpServletRequestFilter might be of some help.
2.  Access the registry through ServletContext using context.getAttribute(TapestryFilter.REGISTRY_CONTEXT_NAME) and then call Registry#getService(Session.class)

regards
Taha



On Feb 19, 2013, at 7:02 PM, dinesh707 wrote:

> I have a HttpServlet inside tapestry project. But I think it is not
> recognized as a part of IoC. So when I do an inject it does not work. It
> ends up throwing a null pointer exception. Any suggestion about how to
> inject the same hibernate session. 
> 
> Thank you 
> 
> 
> 
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/How-to-inject-hibernate-session-into-my-Servlet-tp5720097.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>