-
1. Re: jndi - tomcat - jsp file
zielonyplot Apr 26, 2007 2:39 AM (in response to zielonyplot)"zielonyplot" wrote:
Hi!
I have a little problem: in my jsp file I need to get instance of EntityManager. Could somebody tell me how to do this? In POJO classes I simply use @In annotation, but it doesn't work in jsp files.
Please, help!
I forget - if it is impossible in jsp files, maybe it can be done in servlets? Please, help me how to get EntityManager instance in jsp or servlets. -
2. Re: jndi - tomcat - jsp file
jlaskowski Apr 26, 2007 3:11 AM (in response to zielonyplot)Witaj,
What Tomcat version are you using? If it's lower than Tomcat 6, you should forget about expecting @PersistenceContext to work - servlets are managed components, but only for a servlet container that understands the notion of annotation processing that's introduced in Java EE 5. It should work with Tomcat 6 fine.
Jacek -
3. Re: jndi - tomcat - jsp file
zielonyplot Apr 26, 2007 3:59 AM (in response to zielonyplot)So, in my servlet, I simply need to write something like this:
import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class SomeServlet extends HttpServlet { @PersistenceContext private EntityManager em; public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { List lista = em.createQuery("from Topologia").getResultList(); ........ ........ ........ } }
And It will work, right? -
4. Re: jndi - tomcat - jsp file
pmuir Apr 26, 2007 5:17 AM (in response to zielonyplot)You can't get the EntityManager in a jsp page. If you want it in a servlet and are using a SMPC called entityManager you can do Component.getInstance("entityManager"), but you will need to transaction demarcation yourself. In general Seam/JSF without you needing to mix your presentation and business logic like that (there are still some cases where you have to use a servlet).
-
5. Re: jndi - tomcat - jsp file
zielonyplot Apr 26, 2007 5:36 AM (in response to zielonyplot)So I have one question more: should I write exactly Component.getInstance("entityManager") or it can be Component.getInstance("EntityManager")? Where this String is declared?
-
6. Re: jndi - tomcat - jsp file
pmuir Apr 26, 2007 5:38 AM (in response to zielonyplot)"petemuir" wrote:
using a SMPC called entityManager