[java ee programming] Re: Homework in lab 4203
Hi DELETE p FROM Person p WHERE p.id = ' " +id+ " ' ; Regards - Original Message - From: Biljana Biljana To: J2EE Passion Group Sent: Friday, May 15, 2009 9:44 PM Subject: [java ee programming] Homework in lab 4203 This is my error message when I try to delete one user from person table: HTTP Status 500 - type Exception report message descriptionThe server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: java.lang.IllegalArgumentException: An exception occured while creating a query in EntityManagerroot cause java.lang.IllegalArgumentException: An exception occured while creating a query in EntityManagerroot cause Exception [TOPLINK-8004] (Oracle TopLink Essentials - 2.1 (Build b60e-fcs (12/23/2008))): oracle.toplink.essentials.exceptions.EJBQLException Exception Description: Error compiling the query [Delete from Person p where ID = 39], line 1, column 29: unknown identification variable [id]. The FROM clause of the query does not declare an identification variable [id].note The full stack traces of the exception and its root causes are available in the Sun GlassFish Enterprise Server v2.1 logs. Sun GlassFish Enterprise Server v2.1 My DeletePersonServlet which was called have this code: @PersistenceUnit //The emf corresponding to private EntityManagerFactory emf; @Resource private UserTransaction utx; protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { assert emf != null; //Make sure injection went through correctly. EntityManager em = null; try { //Get the data from user's form HttpSession session = request.getSession(); String id = (String) session.getAttribute("id"); String firstName = (String) session.getAttribute("firstName"); String lastName = (String) session.getAttribute("lastName"); //Create a person instance out of it Person person = new Person(id, firstName, lastName); //begin a transaction utx.begin(); //create an em. //Since the em is created inside a transaction, it is associsated with //the transaction em = emf.createEntityManager(); //delete the person entity Query squery = em.createQuery("Delete from Person p where ID = " + id); //squery.setParameter(1, id); squery.executeUpdate(); //commit transaction which will trigger the em to //commit newly created entity into database utx.commit(); //Forward to ListPerson servlet to list persons along with the newly //created person above request.getRequestDispatcher("ListPerson").forward(request, response); } catch (Exception ex) { throw new ServletException(ex); } finally { //close the em to release any resources held up by the persistebce provider if(em != null) { em.close(); } } } I notice that it took id from last one created person, not from one I want, I set attribute with: But I just dont know how to set right id like is done for because this --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Java EE (J2EE) Programming with Passion!" group. To post to this group, send email to java-ee-j2ee-programming-with-passion@googlegroups.com To unsubscribe from this group, send email to java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en -~--~~~~--~~--~--~---
[java ee programming] Re: Homework in lab 4203
check if the variable 'ID' used in the query Delete from Person p where ID = 39 is correct From: java-ee-j2ee-programming-with-passion@googlegroups.com [mailto:java-ee-j2ee-programming-with-pass...@googlegroups.com] On Behalf Of Biljana Biljana Sent: Friday, May 15, 2009 4:45 PM To: J2EE Passion Group Subject: [java ee programming] Homework in lab 4203 This is my error message when I try to delete one user from person table: HTTP Status 500 - type Exception report message descriptionThe server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: java.lang.IllegalArgumentException: An exception occured while creating a query in EntityManager root cause java.lang.IllegalArgumentException: An exception occured while creating a query in EntityManager root cause Exception [TOPLINK-8004] (Oracle TopLink Essentials - 2.1 (Build b60e-fcs (12/23/2008))): oracle.toplink.essentials.exceptions.EJBQLException Exception Description: Error compiling the query [Delete from Person p where ID = 39], line 1, column 29: unknown identification variable [id]. The FROM clause of the query does not declare an identification variable [id]. note The full stack traces of the exception and its root causes are available in the Sun GlassFish Enterprise Server v2.1 logs. Sun GlassFish Enterprise Server v2.1 My DeletePersonServlet which was called have this code: @PersistenceUnit //The emf corresponding to private EntityManagerFactory emf; @Resource private UserTransaction utx; protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { assert emf != null; //Make sure injection went through correctly. EntityManager em = null; try { //Get the data from user's form HttpSession session = request.getSession(); String id = (String) session.getAttribute("id"); String firstName = (String) session.getAttribute("firstName"); String lastName = (String) session.getAttribute("lastName"); //Create a person instance out of it Person person = new Person(id, firstName, lastName); //begin a transaction utx.begin(); //create an em. //Since the em is created inside a transaction, it is associsated with //the transaction em = emf.createEntityManager(); //delete the person entity Query squery = em.createQuery("Delete from Person p where ID = " + id); //squery.setParameter(1, id); squery.executeUpdate(); //commit transaction which will trigger the em to //commit newly created entity into database utx.commit(); //Forward to ListPerson servlet to list persons along with the newly //created person above request.getRequestDispatcher("ListPerson").forward(request, response); } catch (Exception ex) { throw new ServletException(ex); } finally { //close the em to release any resources held up by the persistebce provider if(em != null) { em.close(); } } } I notice that it took id from last one created person, not from one I want, I set attribute with: But I just dont know how to set right id like is done for because this --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Java EE (J2EE) Programming with Passion!" group. To post to this group, send email to java-ee-j2ee-programming-with-passion@googlegroups.com To unsubscribe from this group, send email to java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en -~--~~~~--~~--~--~---