title: Hibernate inserts null values to table when used with Spring
body: <p>I am trying to use hibernate in Spring and using HSQL DB. I am not able to persist my objects to database since Hibernate does not take the values from object and uses null values instead in the generated Insert statements. I am trying to debug the issue for a while now and have run out of ideas. Any help on the issue is greatly appreciated.</p>
  
  <p>Here are my code snippets. </p>
  
  <p>Application Context (applicationContext.xml): I am configuring my data Source, session Factory, DAO and transaction Manager in the context.</p>
  
  <pre><code>&lt;context:component-scan base-package="com.wb.services.fileservice" /&gt;
  
      &lt;tx:annotation-driven /&gt;
  
  &lt;jdbc:embedded-database id="dataSource"&gt;
      &lt;jdbc:script location="classpath:com/wb/services/testdb/schema.sql" /&gt;
      &lt;jdbc:script location="classpath:com/wb/services/testdb/test-data.sql" /&gt;
  &lt;/jdbc:embedded-database&gt;
  
  &lt;bean id="sessionFactory"
      class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"&gt;
      &lt;property name="dataSource" ref="dataSource" /&gt;
      &lt;property name="mappingResources"&gt;
          &lt;list&gt;
              &lt;value&gt;/com/wb/services/fileservice/file.hbm.xml&lt;/value&gt;
          &lt;/list&gt;
      &lt;/property&gt;
      &lt;property name="hibernateProperties"&gt;
          &lt;props&gt;
              &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.HSQLDialect&lt;/prop&gt;
              &lt;prop key="hibernate.cache.provider_class"&gt;org.hibernate.cache.NoCacheProvider&lt;/prop&gt;
              &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="fileServiceDAO" class="com.wb.services.fileservice.FileServiceDAO"&gt;
      &lt;constructor-arg ref="sessionFactory" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="transactionManager"
      class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
      &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>My Hibernate Mapping file (file.hbm.xml):</p>
  
  <p></p>
  
  <pre><code>&lt;class name="com.wb.services.fileservicemodel.FilePrintHibernate" table="T_FILES"&gt;
  
  &lt;id name="fileID" column="File_ID" type="int"&gt;
          &lt;generator class="native"/&gt;
      &lt;/id&gt;
      &lt;property name="name" column="Name"/&gt;
      &lt;property name="text" column="Text"/&gt;
  &lt;/class&gt;
  </code></pre>
  
  <p></p>
  
  <p>The transient class that needs to be persisted (FilePrintHibernate ):</p>
  
  <pre><code>public class FilePrintHibernate implements Serializable {
  
      private int fileID;
      private String name;
      private String text;
  
  // Skipping getters and setters for the above.
  
  }
  </code></pre>
  
  <p>DAO class that will be persisting the objects to DB table.</p>
  
  <pre><code>@Repository
  
  @Transactional
  
  public class FileServiceDAO {
  
      private SessionFactory sessionFactory;
  
  
      public FileServiceDAO() {
      }
  
      public FileServiceDAO(SessionFactory sessionFactory) {
          this.sessionFactory = sessionFactory;
      }
  
      public SessionFactory getSessionFactory() {
          return sessionFactory;
      }
  
      public Session getCurrentSession() {
          return sessionFactory.getCurrentSession();
      }
  
      @Transactional(readOnly = false, propagation=Propagation.REQUIRED)
      public void findByCreditCard(String filename) {
  
          FilePrintHibernate filePrintHibernate = new FilePrintHibernate();
          filePrintHibernate.setFileID(2);
          filePrintHibernate.setName("Manual");
          filePrintHibernate.setText("Hibernate Test Example");
  
          getCurrentSession().save(filePrintHibernate);
          getCurrentSession().flush();
      }
  }
  </code></pre>
  
  <p>When the app is run and the DAO class (Code file 4 above) tries to persist the FilePrintHibernate object, the insert statement I receive is: <code>insert into T_FILES (File_ID, Name, Text) values (null, ?, ?)</code>. Please note the values it is trying to insert. rather than the values that I set (2,"Manual", "Hibernate Test Example").</p>
  
  <p>Can you please let me know what I am doing wrong above. Any help of the above is really appreciated. </p>
  
  <p>Regards,</p>
  
  <p>Nihil</p>