title: JPA reads but doesn't persists
body: <p>My Java Web App reads data from database but when I try to write something, JPA says ok, but the database does not change. I call "merge" method and the data are not being saved on database, only in memory. I can do a SELECT direct into database and see old data. But the Java Console does not throw any Exception as you can see above.</p>
  
  <p><strong>Java Console:</strong></p>
  
  <pre><code>INFO: [EL Finest]: 2011-10-14 15:02:41.847--UnitOfWork(13027895)--Thread(Thread[http-thread-pool-8080-(6),10,Grizzly])--Merge clone with references user1
  </code></pre>
  
  <p><strong>Change Password's method that is being called:</strong></p>
  
  <pre><code>public static User changePassword(String username, String oldPassword, String newPassword){
          User user = userFacade.find(username);
          if(user != null &amp;&amp; user.getPassword().equals(oldPassword)){
              user.setPassword(newPassword);
              userFacade.edit(user); // supposed to save the new password on database, but it's not
              // at this point, the user has a new password on memory, but on database the password is still the old one
              return user;
          }
          return null;
      }
  </code></pre>
  
  <p><strong>persistence.xml:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"&gt;
      &lt;persistence-unit name="APP1PU" transaction-type="RESOURCE_LOCAL"&gt;
          &lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;/provider&gt;
          &lt;class&gt;com.company.User&lt;/class&gt;
          &lt;properties&gt;
              &lt;property name="javax.persistence.jdbc.url" value="jdbc:mysql://127.0.0.1:3306/app1"/&gt;
              &lt;property name="javax.persistence.jdbc.password" value="12345"/&gt;
              &lt;property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/&gt;
              &lt;property name="javax.persistence.jdbc.user" value="root"/&gt;
              &lt;property name="eclipselink.logging.level" value="FINEST"/&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p><strong>User.java:</strong></p>
  
  <pre><code>@Entity
  @Table(name = "user")
  @Cache (
       type=CacheType.NONE
       )
  public class User implements Serializable {
      private static final long serialVersionUID = 1L;
  
      @Id
      @Basic(optional = false)
      private String username;
  
      @Basic(optional = false)
      private String password;
  
      public String getUsername() {
          return username;
      }
  
      public void setUsername(String username) {
          this.username = username;
      }
  
      public String getPassword() {
          return password;
      }
  
      public void setPassword(String password) {
          this.password = password;
      }
  }
  </code></pre>
  
  <p><strong>UserFacade.java</strong></p>
  
  <pre><code>public class UserFacade {
      private EntityManagerFactory emf = Persistence.createEntityManagerFactory("APP1PU");
  
      private EntityManager em;
  
      protected EntityManager getEntityManager() {
          if( em == null ){
              em = emf.createEntityManager();
          }
          return em;
      }
  
      public void create(User entity) {
          getEntityManager().persist(entity);
      }
  
      public void edit(User entity) {
          getEntityManager().merge(entity);
      }
  
      public void remove(User entity) {
          getEntityManager().remove(getEntityManager().merge(entity));
      }
  
      public User find(Object id) {
          return getEntityManager().find(entityClass, id);
      }
  
  }
  </code></pre>
  
  <p>Anyone can figure why this behavior? Or has some suggestion of a test I could do?</p>
  
  <p>Thanks in advance!</p>