title: upgrading from Hiberante 3 to Hibernate 4 can't persist data to datatbase
body: <p>OK, we have an Hibernate 3 application that I am trying to update to hibernate 4. I can retrieve the data without any problem, but cannot add or update the database. I don't get any error messages, the transaction seems to work, but nothing gets changed in the database. Some help would be greatly appreciated.</p>
  
  <p>Here's the config file hibernate.cfg.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC
      "-//Hibernate/Hibernate Configuration DTD//EN"
      "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"&gt;
  &lt;hibernate-configuration&gt;
    &lt;session-factory&gt;
      &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
      &lt;property name="hibernate.show_sql"&gt;false&lt;/property&gt;
      &lt;property name="hibernate.current_session_context_class"&gt;thread&lt;/property&gt;
      &lt;property name="hibernate.connection.datasource"&gt;jdbc/misc&lt;/property&gt;
      &lt;property name="hibernate.jndi.url"&gt;iiop://127.0.0.1:3700&lt;/property&gt;
      &lt;property name="hibernate.transaction.factory_class"&gt;org.hibernate.transaction.JTATransactionFactory&lt;/property&gt;
      &lt;property name="hibernate.transaction.manager_lookup_class"&gt;org.hibernate.transaction.SunONETransactionManagerLookup&lt;/property&gt;
      &lt;mapping resource="sponsor.hbm.xml"/&gt;
      &lt;mapping resource="portfolio.hbm.xml"/&gt;
      &lt;mapping resource="clientID.hbm.xml"/&gt;
      &lt;mapping resource="legacyID.hbm.xml"/&gt;
      &lt;mapping resource="badClient.hbm.xml"/&gt;
      &lt;mapping resource="language.hbm.xml"/&gt;
    &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>Here's a sam;ole map file of the table I am currently working with sponsor.hbm.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
            "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"&gt;
  &lt;hibernate-mapping&gt;
    &lt;class name="com.lingosys.hibernate.Sponsor" table="sponsor"&gt;
      &lt;id name="companyID" type="integer"&gt;
        &lt;generator class="assigned"/&gt;
      &lt;/id&gt;
      &lt;property name="companyName" type="string"/&gt;
      &lt;property name="sponsorID" type="integer"/&gt;
      &lt;property name="sponsorName" type="string"/&gt;
      &lt;property name="status" type="string"/&gt;
    &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>Here's the class for creating the session factory HibenateUtil.java:</p>
  
  <pre><code>package com.lingosys.hibernate;
  
  
  import org.hibernate.SessionFactory;
  import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
  import org.hibernate.cfg.Configuration;
  import org.hibernate.service.ServiceRegistry;
  
  /**
   * Hibernate Utility class with a convenient method to get Session Factory object.
   *
   * @author mphoenix
   */
  public class HibernateUtil {
      private static final SessionFactory sessionFactory;
  
      static {
          try {
              // Create the SessionFactory from standard (hibernate.cfg.xml) 
              // config file.
              Configuration configuration = new Configuration();
              configuration.configure("hibernate.cfg.xml");
  
              ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(
              configuration.getProperties()).build();
              sessionFactory = configuration.buildSessionFactory(serviceRegistry);
          } catch (Throwable ex) {
              // Log the exception. 
              System.err.println("Initial SessionFactory creation failed." + ex);
              throw new ExceptionInInitializerError(ex);
          }
      }
  
      public static SessionFactory getSessionFactory() {
          return sessionFactory;
      }
  }
  </code></pre>
  
  <p>Here's the dao file SponsorDAO.java:</p>
  
  <pre><code>package com.lingosys.hibernate;
  
  import java.util.List;
  import org.hibernate.Query;
  import org.hibernate.Session;
  
  /**
   *
   * @author mphoenix
   */
  public class SponsorDAO {
      private Session session = null;
  
      public SponsorDAO() {
      }
  
      private void startOperation() {
          session = HibernateUtil.getSessionFactory().openSession();
      }
  
      public void create(Sponsor sponsor) {
          startOperation();
          session.saveOrUpdate("Sponsor", sponsor);
          session.close();
      }
  
  
      public void update(Sponsor sponsor) {
          startOperation();
          session.update("Sponsor", sponsor);
          session.close();
      }
  
      public Sponsor findSponsor(int id) {
          startOperation();
          Sponsor sponsor = (Sponsor) session.get(Sponsor.class, new Integer(id));
          session.close();
          return sponsor;
      }
  
      public List &lt;Sponsor&gt; findAllSponsors() {
          List &lt;Sponsor&gt; sponsors = null;
          startOperation();
          Query query = session.createQuery("from Sponsor");
          sponsors = query.list();
          session.close();
          return sponsors;
      }
  
      public void delete(Sponsor sponsor) {
          startOperation();
          session.delete(sponsor);
          session.close();
      }
  
  }
  </code></pre>
  
  <p>Here's the create transaction code:</p>
  
  <pre><code>UserTransaction tx = null;
  try {
      tx = (UserTransaction)new InitialContext()
                       .lookup("java:comp/UserTransaction");
      tx.begin();
      dao.create(sponsor);
      tx.commit();
  } catch (HibernateException ex) {
      try {
          tx.rollback();
      } catch (Exception ex2) {
          facesCtx.addMessage(null, new FacesMessage("Error on rollback.",
                  ex2.toString()));
      }
      facesCtx.addMessage(null, new FacesMessage("Hibernate Error.",
                  ex.toString()));
      return null;
  } catch (Exception ex) {
      facesCtx.addMessage(null, new FacesMessage("Non-hibernate Error.",
                  ex.toString()));
      return null;
  }
  </code></pre>
  
  <p>Here's a retrieval transaction:</p>
  
  <pre><code>try {
      tx = (UserTransaction)new InitialContext()
                       .lookup("java:comp/UserTransaction");
      tx.begin();
      setSponsorItems(new ArrayList&lt;Sponsor&gt;());
      List&lt;Sponsor&gt; sponsors = dao.findAllSponsors();
      for (Sponsor aSponsor : sponsors) {
          if (companyItemsMap.get(aSponsor.getCompanyID()) != null) {
              getSponsorItems().add(aSponsor);
          }
      }
      tx.commit();
  } catch (HibernateException ex) {
      try {
          tx.rollback();
      } catch (Exception ex2) {
          facesCtx.addMessage(null, new FacesMessage(ex2.toString()));
      }
      facesCtx.addMessage(null, new FacesMessage(ex.toString()));
      return false;
  } catch (Exception ex) {
      facesCtx.addMessage(null, new FacesMessage(ex.toString()));
      return false;
  }
  </code></pre>
  
  <p>And finally the object being mapped to Sponsor.java</p>
  
  <pre><code>package com.lingosys.hibernate;
  
  import java.io.Serializable;
  
  /**
   *
   * @author mphoenix
   */
  public class Sponsor implements Serializable {
      private int companyID;
      private String companyName;
      private int sponsorID;
      private String sponsorName;
      private String status;
  
      public Sponsor() {
      }
  
      public int getCompanyID() {
          return companyID;
      }
  
      public void setCompanyID(int companyID) {
          this.companyID = companyID;
      }
  
      public String getCompanyName() {
          return companyName;
      }
  
      public void setCompanyName(String companyName) {
          this.companyName = companyName;
      }
  
      public int getSponsorID() {
          return sponsorID;
      }
  
      public void setSponsorID(int sponsorID) {
          this.sponsorID = sponsorID;
      }
  
      public String getSponsorName() {
          return sponsorName;
      }
  
      public void setSponsorName(String sponsorName) {
          this.sponsorName = sponsorName;
      }
  
      public String getStatus() {
          return status;
      }
  
      public void setStatus(String status) {
          this.status = status;
      }
  
  
      @Override
      public boolean equals(Object obj) {
          if (obj == null) {
              return false;
          }
          if (getClass() != obj.getClass()) {
              return false;
          }
          final Sponsor other = (Sponsor) obj;
          if (this.companyID != other.companyID) {
              return false;
          }
          return true;
      }
  
      @Override
      public int hashCode() {
          int hash = 5;
          hash = 97 * hash + this.companyID;
          return hash;
      }
  
      //DEBUG CASPERW
      @Override
      public String toString() {
          return "CompanyID: "+companyID+" CompanyName: "+companyName+" SponsorID: "+sponsorID+" SponsorName: "+sponsorName+"\n";
      }
  }
  </code></pre>