Database record not updating But java code says 1 row affected (Primefaces)
<p>i am new to <code>J2EE</code>, i am trying to perform <code>Crud</code> operations. but i am stuck in <code>update method</code>.</p>

<p>i am using <code>EJB</code> for <code>server (database)</code> and <code>jsf-primefaces</code> for <code>client side</code>.</p>

<p>the problem is that whenever i click on <code>edit ajax event</code> it turns my row in to <code>input text</code> which is correct, after that when i edit the fields , i press <code>ok</code> to update the row, but it does'nt.</p>

<p>This is what i have done so far!!!</p>

<p><code>xhtml</code> code:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

&lt;html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core" xml:lang="en" lang="en"
    xmlns:p="http://primefaces.org/ui"&gt;
&lt;h:head&gt;
    &lt;title&gt;JSF 2.x Page&lt;/title&gt;
    &lt;meta http-equiv="keywords" content="enter,your,keywords,here" /&gt;
    &lt;meta http-equiv="description"
        content="A short description of this page." /&gt;
    &lt;meta http-equiv="content-type" content="text/html; charset=UTF-8" /&gt;

    &lt;!--&lt;link rel="stylesheet" type="text/css" href="styles.css"&gt;--&gt;
&lt;/h:head&gt;
&lt;h:body&gt;
&lt;h:form id="form"&gt;
   &lt;p:growl id="msgs" showDetail="true"/&gt;

   &lt;p:dataTable id="rec1" var="item"  value="#{first.list}" paginator="true" editable="true" style="width:550px;" &gt;
       &lt;f:facet name="header"&gt;
           Personal Record
       &lt;/f:facet&gt;

       &lt;p:ajax event="rowEdit" listener="#{first.onRowEdit}" update=":form:msgs" /&gt;
       &lt;p:ajax event="rowEditCancel" listener="#{first.onRowCancel}" update=":form:msgs" /&gt;


       &lt;p:column headerText="Id"&gt;
           &lt;p:cellEditor&gt;
               &lt;f:facet name="output"&gt;&lt;h:outputText value="#{item.id}" /&gt;&lt;/f:facet&gt;
               &lt;f:facet name="input"&gt;&lt;p:inputText id="modelInput" value="#{item.id}" style="width:100%"/&gt;&lt;/f:facet&gt;
           &lt;/p:cellEditor&gt;
       &lt;/p:column&gt;

       &lt;p:column headerText="First Name"&gt;
           &lt;p:cellEditor&gt;
               &lt;f:facet name="output"&gt;&lt;h:outputText value="#{item.fname}" /&gt;&lt;/f:facet&gt;
               &lt;f:facet name="input"&gt;&lt;p:inputText value="#{item.fname}" style="width:100%" label="First Names"/&gt;&lt;/f:facet&gt;
           &lt;/p:cellEditor&gt;
       &lt;/p:column&gt;

       &lt;p:column headerText="Last Name"&gt;
           &lt;p:cellEditor&gt;
               &lt;f:facet name="output"&gt;&lt;h:outputText value="#{item.lname}" /&gt;&lt;/f:facet&gt;
               &lt;f:facet name="input"&gt;&lt;p:inputText value="#{item.lname}" style="width:100%"/&gt;&lt;/f:facet&gt;
           &lt;/p:cellEditor&gt;
       &lt;/p:column&gt;


       &lt;p:column headerText="Delete"&gt;

           &lt;p:commandButton icon="ui-icon-close" title="Delete"
                           actionListener="#{first.removeUser(item)}" update="rec1" /&gt;
      &lt;/p:column&gt;

       &lt;p:column style="width:32px"&gt;
           &lt;p:rowEditor /&gt;
       &lt;/p:column&gt;


  &lt;/p:dataTable&gt;

   &lt;br/&gt;

   &lt;br/&gt;
   &lt;br/&gt;

   &lt;p id="hello"&gt;
First Name:
            &lt;p:inputText value="#{first.fname}"&gt;&lt;/p:inputText&gt;
            &lt;br /&gt; Last Name:
             &lt;p:inputText value="#{first.lname}"&gt;&lt;/p:inputText&gt;
            &lt;br /&gt; 
    &lt;p:growl id="growl" life="5000" /&gt;
   &lt;p:commandButton value="Insert" update="rec1" action="#{first.add}"&gt;&lt;/p:commandButton&gt;

    &lt;br /&gt;&lt;h:messages id="test"&gt;&lt;/h:messages&gt;
&lt;/p&gt;






&lt;/h:form&gt;
&lt;/h:body&gt;
&lt;/html&gt;
</code></pre>

<p>this is my <code>ManagedBean</code></p>

<pre><code>package jsfpckg;

import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
//import javax.faces.bean.ViewScoped;
import javax.ejb.EJB;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;



import org.primefaces.event.RowEditEvent;

import model.User;

import jsfejb.sbeanRemote;

@ManagedBean(name = "first")
@SessionScoped
public class First {



    @EJB(mappedName = "ejb:/ejb/sbean!jsfejb.sbeanRemote")
    sbeanRemote data;

    private List&lt;User&gt; list;
    private String fname;
    private int id;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getFname() {
        return fname;
    }

    public void setFname(String fname) {
        this.fname = fname;
    }

    public String getLname() {
        return lname;
    }

    public void setLname(String lname) {
        this.lname = lname;
    }

    private String lname;

    public void setList(List&lt;User&gt; list) {
        this.list = list;
    }


//    public void onRowEdit(RowEditEvent event) {
//        FacesMessage msg = new FacesMessage("Record Edited", ((user) event.getObject()).getId());
//        FacesContext.getCurrentInstance().addMessage(null, msg);
//    }
//     
//    public void onRowCancel(RowEditEvent event) {
//        FacesMessage msg = new FacesMessage("Edit Cancelled", ((user) event.getObject()).getId());
//        FacesContext.getCurrentInstance().addMessage(null, msg);
//    }

    public List&lt;User&gt; getList() {

        list = data.retriveDatatypes();
     //   System.out.println("list in first class is" + list.get(1));
        return list;

    }


    public String add() {

        data.insertUser(fname, lname);
        FacesContext.getCurrentInstance().addMessage(" Succesfully added to database ",
                new javax.faces.application.FacesMessage("Succesfully added to database"));
         return "Null";
    }

        public void removeUser(User user){

            System.out.println("deleted");
        int id= user.getId();
        //int user1= ((User) event.getObject()).getId();
        data.deleteUser(id);


    }



    public void onRowEdit(RowEditEvent event) {


        int user1= ((User) event.getObject()).getId();
        String fname1= ((User) event.getObject()).getFname();
        String lname1= ((User) event.getObject()).getLname();


        //list.remove(list.get(user1));
        data.saveUser(user1, fname1, lname1);
        System.out.println("name., id, is "+user1+fname1+lname1);
        FacesMessage msg = new FacesMessage("Record Edited for ID: "+user1);
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }


    public void onRowCancel(RowEditEvent event) {
        FacesMessage msg = new FacesMessage("Edit Cancelled");
        FacesContext.getCurrentInstance().addMessage(null, msg);
    }



}
</code></pre>

<p>and this is my <code>EJB</code> project <code>bean</code> file where i have written all queries</p>

<pre><code>public void saveUser(int id, String fname, String lname) {
        System.out.println("recieveing records: "+id+fname+lname);
        String query = "UPDATE user SET fname='"+fname+"', lname='"+lname+"' where id= "+id;
</code></pre>

<p>//       int outcome = em.createNativeQuery(query).executeUpdate();</p>

<pre><code>//      User user= em.find(User.class, id);
//      user.setFname(fname);
//      user.setLname(lname);
//      em.persist(user);
//      em.merge(user);

        System.out.println("outcome"+ outcome);
    }
</code></pre>

<blockquote>
  <p>Note: this thing worked for <code>update</code> but i don't want to use this</p>
</blockquote>

<pre><code>            User user= em.find(User.class, id);
            user.setFname(fname);
            user.setLname(lname);
            em.persist(user);
            em.merge(user);
</code></pre>

<p><a href="https://i.stack.imgur.com/TXdR4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TXdR4.png" alt="this is the main table"></a>
<a href="https://i.stack.imgur.com/6Dyx9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6Dyx9.png" alt="appears after clicking edit"></a></p>

<p><a href="https://i.stack.imgur.com/cwTIG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cwTIG.png" alt="says record edited!!! but didnt changed the database values. the query result also shows 1 which means row 1 row is affected"></a></p>