3 Replies Latest reply on Jan 5, 2015 11:24 AM by Scott Marlow

    javax.persistence.NoResultException: No entity found for query  on wildfly8/9

    Gulam Samdani Expert

      wildfly 9 problem : JPA2.1

       

      I have done exception handle for no data in table . but wildfly give error message .

       

      javax.ejb.EJBException: javax.persistence.NoResultException: No entity found for query

       

      any please help me ?

       

      My Servlet is :

       

      ---------------------------------------

       

             @EJB

          private CustomerGateway customerService;

       

          protected void doGet(HttpServletRequest request,

                  HttpServletResponse response) throws ServletException, IOException {

       

              PrintWriter pw = response.getWriter();

              try {

       

                  Customer customerDetail = customerService.CustomerDetail(6);

       

                  pw.println("dhaka ...web" + customerDetail.getName());

       

              } catch (NoResultException e) {

       

                  pw.println("dhaka ...web exception*** " + e.getMessage());

              }

       

          }

       

       

          Service :

       

          =================================================

          @TransactionAttribute(TransactionAttributeType.SUPPORTS)

          public Customer listCustomerDetail(Integer id)throws NoResultException {

       

                  return customerGateway.CustomerDetail(id);

          }

                          DAO :

       

          ---------------------------------------

       

          public Customer CustomerDetail(Integer id)throws NoResultException {

       

                  Query query = em.createNativeQuery(

                          "SELECT * FROM customer where id =:id", Customer.class);

                  query.setParameter("id", id);

       

                  Customer rs = null;

                  rs = (Customer) query.getSingleResult();

                  return rs;

          }