title: Persisted objects overwrite the last record instead of creating a new one with Spring MVC, Google App Engine, JDO3
body: <p>I'm using Spring MVC 3.1.2 with Google App Engine. I have a problem with persisting objects in the data store using JDO3. The weird problem is that whenever I persist objects (during  a short period of time) the last added object doesn't get persisted in a new record it just overwrites the last record keeping the same id (the id of the last record). Here are  the files that could be concerned. </p>
  
  <p>User.java</p>
  
  <pre><code>@Component
  @PersistenceCapable
  public class User {
  
      @PrimaryKey
      @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
      private Long id;
  
      @Persistent
      private String firstName;
      @Persistent
      private String lastName;
      @Persistent
      private String email;
      @Persistent
      private String password;
  
      public Long getId() {
          return id;
      }
      public String getFirstName() {
          return firstName;
      }
      public String getLastName() {
          return lastName;
      }
      public String getEmail() {
          return email;
      }
      public String getPassword() {
          return password;
      }
      public void setId(Long id) {
          this.id = id;
      }
      public void setFirstName(String firstName) {
          this.firstName = firstName;
      }
      public void setLastName(String lastName) {
          this.lastName = lastName;
      }
      public void setEmail(String email) {
          this.email = email;
      }
      public void setPassword(String password) {
          this.password = password;
      }   
  
  }   
  </code></pre>
  
  <p>UserDaoImpl.java</p>
  
  <pre><code>@Repository
  public class UserDaoImpl implements UserDao {
  
      private static PersistenceManager pm;
  
      @Override
      public void add(User user) {
  
          if (pm == null || pm.isClosed()) {
              pm = PMF.get().getPersistenceManager();
          }
  
          try {
  
          pm.makePersistent(user);    
          } finally {
  
          pm.close();
  
          }
      }
  
  }
  </code></pre>
  
  <p>PMF.java</p>
  
  <pre><code>public final class PMF {
      private static final PersistenceManagerFactory pmfInstance =
          JDOHelper.getPersistenceManagerFactory("transactions-optional");
  
      private PMF() {}
  
      public static PersistenceManagerFactory get() {
          return pmfInstance;
      }
  }
  </code></pre>
  
  <p>UserController.java</p>
  
  <pre><code>@Controller
  public class UserController {
  
      @Autowired
      UserService userService;
  
      @Autowired
      User user;
  
  
      @RequestMapping(value="/adduser", method=RequestMethod.GET)
      String adduser(){
  
          return "adduser";
  
      }
  
      @RequestMapping(value="/adduser.do", method=RequestMethod.POST)
      String saveUserr(@RequestParam String firstname,@RequestParam String lastname,   @RequestParam String email, @RequestParam String password){
  
  
          this.user.setFirstName(firstname);
          this.user.setLastName(lastname);
          this.user.setEmail(email);
          this.user.setPassword(password);
          userService.add(user);//this invokes the UseDaoImpl add(user)
  
      }
  }
  </code></pre>
  
  <p>jdoconfig.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;jdoconfig xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig_3_0.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig http://java.sun.com/xml/ns/jdo/jdoconfig_3_0.xsd"&gt;
  
     &lt;persistence-manager-factory name="transactions-optional"&gt;
         &lt;property name="javax.jdo.PersistenceManagerFactoryClass"
             value="org.datanucleus.api.jdo.JDOPersistenceManagerFactory"/&gt;
         &lt;property name="javax.jdo.option.ConnectionURL" value="appengine"/&gt;
         &lt;property name="javax.jdo.option.NontransactionalRead" value="true"/&gt;
         &lt;property name="javax.jdo.option.NontransactionalWrite" value="true"/&gt;
         &lt;property name="javax.jdo.option.RetainValues" value="true"/&gt;
         &lt;property name="datanucleus.appengine.autoCreateDatastoreTxns" value="true"/&gt;
         &lt;property name="datanucleus.appengine.singletonPMFForName" value="true"/&gt;
     &lt;/persistence-manager-factory&gt;
  &lt;/jdoconfig&gt;
  </code></pre>