title: hibernate annotation- inheritance with @MappedSuperclass - values are not being set to base class fields- strange error
body: <p>I was following  <a href="http://ocpsoft.org/java/hibernate-use-a-base-class-to-map-common-fields/" rel="nofollow">Hibernate: Use a Base Class to Map Common Fields</a>   and  <a href="http://openjpa.apache.org/builds/1.0.2/apache-openjpa-1.0.2/docs/manual/jpa_overview_mapping_inher.html" rel="nofollow">openjpa inheritance tutorial</a>   to put common columns like ID, lastModifiedDate etc in base table.</p>
  
  <p>My annotated mappings are as follow :</p>
  
  <p><strong>BaseTable :</strong></p>
  
  <pre><code>@MappedSuperclass
  public abstract class BaseTable {
      @Id
      @GeneratedValue
      @Column(name = "id")
      private int id;
  
      @Column(name = "lastmodifieddate")
      private Date lastModifiedDate;
  ...
  </code></pre>
  
  <p><strong>Person table -</strong></p>
  
  <pre><code>    @Entity
      @Table(name = "Person ")
      public class Person extends BaseTable  implements Serializable{
  
      @Column(name = "name")
      private String name;
  ...
  </code></pre>
  
  <p><strong>Create statement generated :</strong></p>
  
  <pre><code>create table Person (id integer not null auto_increment,  lastmodifieddate datetime, name varchar(255), primary key (id)) ; 
  </code></pre>
  
  <p>After I save a Person object to db, </p>
  
  <pre><code>Person p = new Person();
  p.setName("Test");
  p.setLastModifiedDate(new Date());
  ..
  
  getSession().save(p);
  </code></pre>
  
  <p>I am setting the date field but, it is saving the record with generated ID and LastModifiedDate = null, and Name="Test".</p>
  
  <p><strong>Insert Statement :</strong></p>
  
  <pre><code>insert into Person (lastmodifieddate, name) values (?, ?)
  binding parameter [1] as [TIMESTAMP] - &lt;null&gt;
  binding parameter [2] as [VARCHAR] - Test
  </code></pre>
  
  <p><strong>Read by ID query :</strong>
  When I do hibernate query (get By ID) as below, It reads person by given ID.</p>
  
  <pre><code>Criteria c = getSession().createCriteria(Person.class);
  c.add(Restrictions.eq("id", id));
  Person person= c.list().get(0);
  //person has generated ID, LastModifiedDate is null
  
  select query select person0_.id as id8_,  person0_.lastmodifieddate as lastmodi8_, person0_.name as name8_ from Person person0_
   - Found [1] as column [id8_]
   - Found [null] as column [lastmodi8_]
   - Found [Test] as column [name8_ ]
  </code></pre>
  
  <p><strong>ReadAll query :</strong></p>
  
  <pre><code>Query query = getSession().createQuery("from " + Person.class.getName());
  List&lt;Person&gt; allPersons=query.list();
  </code></pre>
  
  <p>Corresponding SQL for read all</p>
  
  <pre><code>select query select person0_.id as id8_,  person0_.lastmodifieddate as lastmodi8_, person0_.name as name8_ from Person person0_
  - Found [1] as column [id8_]
  - Found [null] as column [lastmodi8_]
  - Found [Test] as column [name8_ ]
  - Found [2] as column [id8_]
  - Found [null] as column [lastmodi8_]
  - Found [Test2] as column [name8_ ]
  </code></pre>
  
  <p>But when I print out the list in console, its being more weird.  it is selecting List of Person object with </p>
  
  <ul>
  <li>ID fields = all 0 (why all 0 ?)</li>
  <li>LastModifiedDate = null  </li>
  <li>Name fields have valid values</li>
  </ul>
  
  <p>I don't know whats wrong here. Could you please look at it?</p>
  
  <p><strong>FYI,</strong></p>
  
  <p>My Hibernate-core version : 4.1.2, MySQL Connector version : 5.1.9 .</p>
  
  <p><strong>In summary, There are two issues here</strong></p>
  
  <ul>
  <li>Why I am getting All ID Fields =0 when using read all?</li>
  <li>Why the LastModifiedDate is not being inserted?</li>
  </ul>