title: How to set different types for getter, setter and database field with Hibernate?
body: <p>I have a timestamp field in H2 database, but I need to get String instead of Date from my bean using Hibernate 4.3, so I'm trying to do like that in my bean:</p>
  
  <pre><code>import java.util.Date;
  
  ...
  
  private Date msgDate;
  @Column(name = "msgDate", columnDefinition="timestamp")
  public String getMsgDate() {
      SimpleDateFormat df = new SimpleDateFormat("yyyy MM dd HH mm ss");
      return df.format(msgDate);
  }
  
  public void setMsgDate(Date msgDate) {
      this.msgDate = msgDate;
  }
  </code></pre>
  
  <p>But I have next errors:</p>
  
  <pre><code>    ERROR: HHH000123: IllegalArgumentException in class: Messages, setter method of property: msgDate
  июл 03, 2013 11:39:56 AM org.hibernate.property.BasicPropertyAccessor$BasicSetter set
  ERROR: HHH000091: Expected type: java.util.Date, actual value: java.lang.String
  июл 03, 2013 11:39:56 AM org.apache.catalina.core.StandardWrapperValve invoke
  SEVERE: Servlet.service() for servlet [MessageList] in context with path [/messenger] threw exception
  org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of com.epam.epamlab.messenger.beans.Messages.msgDate
      at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:119)
      at org.hibernate.tuple.entity.AbstractEntityTuplizer.setPropertyValues(AbstractEntityTuplizer.java:711)
      at org.hibernate.tuple.entity.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:371)
      at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:4519)
      at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:188)
      at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:144)
      at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:1102)
      at org.hibernate.loader.Loader.processResultSet(Loader.java:959)
      at org.hibernate.loader.Loader.doQuery(Loader.java:906)
      at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:340)
      at org.hibernate.loader.Loader.doList(Loader.java:2523)
      at org.hibernate.loader.Loader.doList(Loader.java:2509)
      at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2339)
      at org.hibernate.loader.Loader.list(Loader.java:2334)
      at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:491)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:369)
      at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:222)
      at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1270)
      at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
      ...
  Caused by: java.lang.IllegalArgumentException: argument type mismatch
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:601)
      at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:65)
      ... 40 more
  </code></pre>
  
  <p>If I returns Date from getter, everything works nice. Why Hibernate waits Date type to be returned, even after using columnDefinition in annotations? How I should do this correctly?</p>