title: I have used SelectBeforeUpdate but every time i persist a detached object without any changes hibernate is saving with column value with null
body: <p>I have started using hibernate and im not a pro. I am trying to implement an example to turn a detached object to persistence object .
  I am getting this error.
  I have used SelectBeforeUpdate but every time i persist a detached object without any changes hibernate is saving with column value with null.  </p>
  
  <p>Entity class is :</p>
  
  <pre><code>import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.Table;
  
  import org.hibernate.annotations.DynamicUpdate;
  import org.hibernate.annotations.SelectBeforeUpdate;
  
  @Entity
  @Table (name="USER_DETACHED")
  @SelectBeforeUpdate
  @DynamicUpdate
  public class UserDetails {
  
      @Id @GeneratedValue(strategy=GenerationType.AUTO)
      private int userId;
  
      private String userName;
  
      public int getUserId() {
          return userId;
      }
  
      public void setUserId(int userId) {
          this.userId = userId;
      }
  
      public String getUserName() {
          return userName;
      }
  
      public void setUserName(String userName) {
          this.userName = userName;
      }   
  }
  
   &gt; ##  Main Method is: I have tried using generatedValue alone and with strategy auto also ... it didnt work ##
  
  
  public class TestCrud {
  
      public static void main(String[] args) {
          UserDetails user= new UserDetails();
          Configuration configuration = newConfiguration().configure("hibernate.cfg.xml");
          ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build(); 
          SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
          Session session = sessionFactory.openSession();
          session.beginTransaction();
          user = (UserDetails) session.get(UserDetails.class,1);
          System.out.println(user.getUserId() +   "         " + user.getUserName());
          session.getTransaction().commit();
          session.close();
  
          session = sessionFactory.openSession();
          session.beginTransaction();
          session.save(user);
          session.getTransaction().commit();
          session.close();
      }
  }
  </code></pre>
  
  <p>My StackTrace is:</p>
  
  <pre><code>    Jul 05, 2015 10:44:45 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager &lt;clinit&gt;
      INFO: HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
      Jul 05, 2015 10:44:45 PM org.hibernate.Version logVersion
      INFO: HHH000412: Hibernate Core {4.3.10.Final}
      Jul 05, 2015 10:44:45 PM org.hibernate.cfg.Environment &lt;clinit&gt;
      INFO: HHH000206: hibernate.properties not found
      Jul 05, 2015 10:44:45 PM org.hibernate.cfg.Environment buildBytecodeProvider
      INFO: HHH000021: Bytecode provider name : javassist
      Jul 05, 2015 10:44:45 PM org.hibernate.cfg.Configuration configure
      INFO: HHH000043: Configuring from resource: hibernate.cfg.xml
      Jul 05, 2015 10:44:45 PM org.hibernate.cfg.Configuration getConfigurationInputStream
      INFO: HHH000040: Configuration resource: hibernate.cfg.xml
      Jul 05, 2015 10:44:45 PM org.hibernate.cfg.Configuration doConfigure
      INFO: HHH000041: Configured SessionFactory: null
      Jul 05, 2015 10:44:45 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
      WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!)
      Jul 05, 2015 10:44:46 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
      INFO: HHH000401: using driver [oracle.jdbc.driver.OracleDriver] at URL [jdbc:oracle:thin:@localhost:1521:xe]
      Jul 05, 2015 10:44:46 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
      INFO: HHH000046: Connection properties: {user=hr, password=****}
      Jul 05, 2015 10:44:46 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
      INFO: HHH000006: Autocommit mode: false
      Jul 05, 2015 10:44:46 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
      INFO: HHH000115: Hibernate connection pool size: 1 (min=1)
      Jul 05, 2015 10:44:46 PM org.hibernate.dialect.Dialect &lt;init&gt;
      INFO: HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect
      Jul 05, 2015 10:44:47 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
      INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
      Jul 05, 2015 10:44:47 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory &lt;init&gt;
      INFO: HHH000397: Using ASTQueryTranslatorFactory
      Jul 05, 2015 10:44:47 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
      INFO: HHH000228: Running hbm2ddl schema update
      Jul 05, 2015 10:44:47 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
      INFO: HHH000102: Fetching database metadata
      Jul 05, 2015 10:44:47 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
      INFO: HHH000396: Updating schema
      Jul 05, 2015 10:44:47 PM org.hibernate.tool.hbm2ddl.TableMetadata &lt;init&gt;
      INFO: HHH000261: Table found: HR.USER_DETACHED
      Jul 05, 2015 10:44:47 PM org.hibernate.tool.hbm2ddl.TableMetadata &lt;init&gt;
      INFO: HHH000037: Columns: [userid, username]
      Jul 05, 2015 10:44:47 PM org.hibernate.tool.hbm2ddl.TableMetadata &lt;init&gt;
      INFO: HHH000108: Foreign keys: []
      Jul 05, 2015 10:44:47 PM org.hibernate.tool.hbm2ddl.TableMetadata &lt;init&gt;
      INFO: HHH000126: Indexes: [sys_c008436]
      Jul 05, 2015 10:44:47 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
      INFO: HHH000232: Schema update complete
      Hibernate: select userdetail0_.userId as userId1_0_0_, userdetail0_.userName as userName2_0_0_ from USER_DETACHED userdetail0_ where userdetail0_.userId=?
      1         Sandeep
      Hibernate: select hibernate_sequence.nextval from dual
      Hibernate: insert into USER_DETACHED (userName, userId) values (?, ?)
  </code></pre>