title: Hibernate update all columns from object
body: <p>I have the following method to update a row in database using hibernate. I want to update all the columns in the table using the new object. So I get the existing object and set all of its properties to the new object's properties.</p>
  
  <pre><code>public void updatePlace(Place newPlace) {
      Session session = factory.openSession();
      Transaction tx = null;
      try {
          tx = session.beginTransaction();
          Place place = (Place)session.createQuery("FROM Place AS plc WHERE plc.Id = " + newPlace.getId()).list().get(0);
          place.setPhone(newPlace.getPhone());
          place.setPKey(newPlace.getPKey());
          place.setName(newPlace.getName());
          place.setDetails(newPlace.getDetails());
          session.update(place);
          tx.commit();
      } catch (HibernateException e) {
          if (tx != null) {
              tx.rollback();
          }
          e.printStackTrace();
      } finally {
          session.close();
      }
  }
  </code></pre>
  
  <p>In this method I update all the columns one by one, and if I add a new column one day I have to remember to change this method.</p>
  
  <pre><code>place.setPhone(newPlace.getPhone());
  place.setPKey(newPlace.getPKey()); 
  place.setName(newPlace.getName());
  place.setDetails(newPlace.getDetails());
  </code></pre>
  
  <p>Is there a shorter way to update the columns using the newPlace object?</p>