title: Hibernate doesn't update record in MySQL database
body: <p>I am using <code>PrimeFaces 3.5</code>, <code>JSF 2.2</code>, <code>Hibernate 4.1</code>, <code>Spring 3.2.3</code>, <code>MySQL</code> in my application.
  Function updateUser() is supposed to update record in the database for the selected user from the PrimeFaces dataTable component(values are correct) but for some unknown reason it doesn't. I have a class named AbstractDAO which implements CRUD operations via generics. Insertion, selection and deleting works perfectly, but update fails without showing any errors at all. Any clues what can be wrong in my code?</p>
  
  <hr>
  
  <p>applicationContext.xml:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xmlns:tx="http://www.springframework.org/schema/tx"
         xmlns:context="http://www.springframework.org/schema/context"
         xmlns:sec="http://www.springframework.org/schema/security"
         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd"&gt;
  
  
      &lt;!--            GLOABL SETTINGS             --&gt;
  
  
      &lt;context:component-scan base-package="com.infostroy.adminportal"/&gt;
      &lt;tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/&gt;
  
  
      &lt;!--        DATA SOURCE AND PERSISTENCE SETTINGS       --&gt;
  
  
      &lt;bean id="propertiesPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;
          &lt;property name="locations"&gt;
              &lt;list&gt;
                  &lt;value&gt;classpath:db.properties&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dmDataSource"/&gt;
          &lt;property name="packagesToScan" value="com.infostroy.adminportal"/&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.dialect"&gt;${db.dialect}&lt;/prop&gt;
                  &lt;prop key="hibernate.show_sql"&gt;${db.show_sql}&lt;/prop&gt;
                  &lt;prop key="hibernate.hbm2ddl.auto"&gt;${db.hbm2ddl_auto}&lt;/prop&gt;
                  &lt;prop key="connection.pool_size"&gt;${db.pool_size}&lt;/prop&gt;
                  &lt;prop key="current_session_context_class"&gt;${db.current_session_context_class}&lt;/prop&gt;
                  &lt;prop key="org.hibernate.FlushMode"&gt;${db.flush_mode}&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
  
      &lt;bean id="transactionManager"
            class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
          &lt;property name="dataSource" ref="dmDataSource" /&gt;
          &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
      &lt;/bean&gt;
  
  
      &lt;bean id="dmDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;
          &lt;property name="driverClassName" value="${db.driver}" /&gt;
          &lt;property name="url" value="${db.url}" /&gt;
          &lt;property name="username" value="${db.username}" /&gt;
          &lt;property name="password" value="${db.password}" /&gt;
          &lt;property name="maxWait" value="5000" /&gt;
          &lt;property name="initialSize" value="2" /&gt;
          &lt;property name="maxActive" value="100"/&gt;
          &lt;property name="maxIdle" value="50"/&gt;
          &lt;property name="minIdle" value="0"/&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>db.properties:</p>
  
  <pre><code>db.username=root
  db.password=root
  db.driver=com.mysql.jdbc.Driver
  db.url=jdbc:mysql://localhost/adminportal
  db.pool_size=0
  db.dialect=org.hibernate.dialect.MySQLDialect
  db.hbm2ddl_auto=validate
  db.show_sql=true
  db.current_session_context_class=thread
  db.flush_mode=COMMIT
  </code></pre>
  
  <p>AbstractDAO:</p>
  
  <pre><code>public abstract class AbstractDAO&lt;T extends Serializable&gt; implements Serializable {
  
  @Autowired
  protected SessionFactory sessionFactory;
  protected T object;
  protected Class clazz;
  
  public AbstractDAO(Class clazz) {
      this.clazz = clazz;
  }
  
  //Executes before being removed from container
  @PreDestroy
  protected void destroy() {
      sessionFactory.getCurrentSession().close();
  }
  
  public Session getHiberSession() {
      return sessionFactory.openSession();
  }
  
  @Transactional
  protected T getByID(int id) {
      String queryString = "from " + clazz.getSimpleName() + " where id = :id";
      Query query = getHiberSession().createQuery(queryString);
      query.setInteger("id", id);
      object = (T) query.uniqueResult();
      return object;
  }
  
  @Transactional
  protected int deleteByID(int id) {
      String queryString = "delete " + clazz.getSimpleName() + " where id = :id";
      Query query = getHiberSession().createQuery(queryString);
      query.setInteger("id", id);
      return query.executeUpdate();
  }
  
  @Transactional
  protected boolean insert(T object) {
      try {
          getHiberSession().save(object);
          return true;
      } catch (HibernateException ex) {
          return false;
      }
  }
  
  @Transactional
  protected boolean update(T object) {
      try {
          getHiberSession().saveOrUpdate(object);
          return true;
      } catch (HibernateException ex) {
          return false;
      }
  }
  
  @Transactional
  protected List getAllRecords() {
      String queryString = "from " + clazz.getSimpleName();
      Query query = getHiberSession().createQuery(queryString);
      return query.list();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>UserDAO.java:</p>
  
  <pre><code>@Repository
  public class UserDAO extends AbstractDAO&lt;User&gt; {
  
  public UserDAO() {
      super(User.class);
  }
  
  public User getUserById(int id) {
      return super.getByID(id);
  }
  
  public int deleteUserById(int id) {
      return super.deleteByID(id);
  }
  
  public boolean insertUser(User user) {
      return super.insert(user);
  }
  
  public boolean updateUser(User user) {
      return super.update(user);
  }
  
  public List&lt;User&gt; getAllUsers() {
      return super.getAllRecords();
  }
  }
  </code></pre>
  
  <hr>
  
  <p>If you need any additional info or code - just tell me. Every answer is highly appreciated and responded immidiately.</p>
  
  <p>Thank you.</p>