title: java/Spring Hibernate not updating entities
body: <p>I have read and reread everything here on SO and many other sites but can't seem to figure out why my updated objects are not updating.  </p>
  
  <p>The basic overview of what I'm doing:</p>
  
  <ol>
  <li><p>Service layer asks DAO for some <em>People</em></p></li>
  <li><p>Return an ArrayList of <em>People</em> from the DB (DAO / @Repository)</p></li>
  <li><p>Service Layer manipulates object and adds them to a new arraylist</p></li>
  <li><p>Service Layers passes new list back to DAO to update</p></li>
  <li><p><strong>NOTHING GETS Updated</strong></p></li>
  </ol>
  
  <p><em>If I throw a log message in my object has the new values, the children are correctly hydrated.  I get no errors in the code is just doesn't commit my changes.</em></p>
  
  <p>Here is some code:</p>
  
  <p><strong>PersonDAO</strong> <em>annotated as @Repository</em></p>
  
  <pre><code>public void updatePeople(List&lt;Person&gt; people) {
      log.info("Updating " + people.size() + " people");
      try {
          Transaction tx = getCurrentSession().beginTransaction();
          for (Person person : people){
              getCurrentSession().saveOrUpdate(person);
          }
          getCurrentSession().flush();
          tx.commit();
          getCurrentSession().close();
  
      } catch (Exception e){
          log.error("Exception Updating all people " + e.toString());
          e.printStackTrace();
      }
  
  }
  
  public List&lt;Person&gt; getAssociatesByStoreId(String storeId) {
      try {
  
          List&lt;Person&gt; usersInStore = (List&lt;Person&gt;) getCurrentSession()
                  .createCriteria(Person.class).createCriteria("store")
                  .add(Restrictions.eq("storeId", storeId)).list();
  
          return usersInStore;
      } catch (Exception e) {
          log.error("exception in getAssociatesByStoreId ", e);
      }
      return null;
  }
  </code></pre>
  
  <p><strong>PersonService</strong> <em>annotated as @Service</em> - relevant method</p>
  
  <pre><code>/* I put the people into a map to do some other logic on them */
  for (Person person : personDAO.getAllPeople()){
              personMap.put(person.getEmployeeId() + "-" + person.getStore().getStoreId(), person);
  }
  
  /*    
   I iterate a list creating new Person objects (based on some random stuff), 
   including saving any children entities (managementcodes and stores) that need to be created
   After I have created a new Person I attempt to find it in the map from above.  
   If I find it pull it out of the map and put it into an array list 
   that is eventually passed back into the DAO
  */
  </code></pre>
  
  <p><strong>Person</strong> <em>annotated as @Entity</em></p>
  
  <pre><code>private int personid;
  private String firstName;
  private String lastName;
  private Store store;
  private ManagementCode managementCode;
  
  @Id
  @GeneratedValue(strategy=GenerationType.AUTO)
  @Column(name = "personid", unique = true, nullable = false)
  public int getPersonid() {
      return this.personid;
  }
  
      /*a bunch of getters and setters*/
  @ManyToOne(fetch = FetchType.LAZY, optional = true, cascade = {CascadeType.MERGE, CascadeType.PERSIST})
  @org.hibernate.annotations.Cascade( {org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.PERSIST})
  @LazyCollection(LazyCollectionOption.EXTRA)
  @JoinColumn(name = "managementlevel", nullable = true)
  public ManagementCode getManagementCode() {
      return this.managementCode;
  }
  
  @ManyToOne(fetch = FetchType.LAZY, optional = true, cascade = {CascadeType.MERGE, CascadeType.PERSIST})
  //  @org.hibernate.annotations.Cascade( {org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.PERSIST})
  @JoinColumn(name = "storeid", nullable = false)
  public Store getStore() {
      return this.store;
  }
  </code></pre>
  
  <p><strong>Store</strong> annotated as entity <em>(Managementcode is the same)</em></p>
  
  <pre><code>/*fields + getters and setter */
  @OneToMany(fetch = FetchType.LAZY, mappedBy = "store", cascade = {CascadeType.MERGE, CascadeType.PERSIST})
  @LazyCollection(LazyCollectionOption.EXTRA)
  @JsonIgnore 
  public Set&lt;Person&gt; getPersons() {
      return this.persons;
  }
  </code></pre>
  
  <p><strong>EDIT</strong>  I added both sets of Cascade type annotations above and still no luck</p>
  
  <p><strong>EDIT 2</strong>  Updated the to show the primary key definition
  Someone please help me before I kick a puppy.
  Thanks</p>