title: Hibernate ClassCastException org.hibernate.type.SerializableType cannot be cast to org.hibernate.type.VersionType
body: <p>I have an odd exception appearing when I try to run a unit test. Here is the stack trace:</p>
  
  <pre><code>javax.persistence.PersistenceException: [PersistenceUnit: testPU] Unable to build Hibernate SessionFactory
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:1249)
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.access$600(EntityManagerFactoryBuilderImpl.java:120)
       ... more
  Caused by: org.hibernate.MappingException: Could not instantiate persister org.hibernate.persister.entity.SingleTableEntityPersister
      at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:174)
      at org.hibernate.persister.internal.PersisterFactoryImpl.createEntityPersister(PersisterFactoryImpl.java:135)
      at org.hibernate.internal.SessionFactoryImpl.&lt;init&gt;(SessionFactoryImpl.java:401)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1859)
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857)
      ... 39 more
  Caused by: java.lang.ClassCastException: org.hibernate.type.SerializableType cannot be cast to org.hibernate.type.VersionType
      at org.hibernate.tuple.PropertyFactory.buildVersionProperty(PropertyFactory.java:181)
      at org.hibernate.tuple.entity.EntityMetamodel.&lt;init&gt;(EntityMetamodel.java:218)
      at org.hibernate.persister.entity.AbstractEntityPersister.&lt;init&gt;(AbstractEntityPersister.java:520)
      at org.hibernate.persister.entity.SingleTableEntityPersister.&lt;init&gt;(SingleTableEntityPersister.java:148)
      at sun.reflect.GeneratedConstructorAccessor29.newInstance(Unknown Source)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
      at org.hibernate.persister.internal.PersisterFactoryImpl.create(PersisterFactoryImpl.java:163)
      ... 43 more
  </code></pre>
  
  <p>Here are the libraries and frameworks that I'm using:</p>
  
  <ol>
  <li>JPA 2.0</li>
  <li>org.hibernate:hibernate-entitymanager:4.3.5.Final</li>
  <li>com.h2database:h2:1.4.188</li>
  <li>junit:junit:4.11</li>
  <li>Intellij IDE (I'm just running the test here)</li>
  <li>org.hibernate:hibernate-envers:4.3.5.Final</li>
  </ol>
  
  <p>Well, I bet anyone who looks at this wants to see the persistense.xml file so here it is:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0"&gt;
      &lt;persistence-unit name="testPU" transaction-type="RESOURCE_LOCAL"&gt;
          &lt;provider&gt;org.hibernate.jpa.HibernatePersistenceProvider&lt;/provider&gt;
          &lt;exclude-unlisted-classes&gt;true&lt;/exclude-unlisted-classes&gt;
  </code></pre>
  
  <p>There are many classes here so I've cut them out to keep things readable</p>
  
  <pre><code>        &lt;properties&gt;
              &lt;property name="javax.persistence.jdbc.driver" value="org.h2.Driver" /&gt;
              &lt;property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test;MODE=PostgreSQL;INIT=create schema if not exists test;DB_CLOSE_DELAY=-1" /&gt;
              &lt;property name="javax.persistence.jdbc.user" value="sa" /&gt;
              &lt;property name="javax.persistence.jdbc.password" value="" /&gt;
              &lt;property name="hbm2ddl.auto" value="create" /&gt;
              &lt;property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL9Dialect"/&gt;
              &lt;property name="hibernate.show_sql" value="false"/&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>The unit test is basic. It just finds a record by a value. Here is the code:</p>
  
  <pre><code>@Test
    public void testFindByNaturalKeyReturnsBusinessUnit() {
      final BusinessUnit businessUnit = mock(BusinessUnit.class);
      assertThat(businessUnitDao.findByNaturalKey(businessUnit.getNaturalKey()).getId(), is(businessUnit.getId()));
    }
  </code></pre>
  
  <p>Finally, the entity is really complex. I'm not sure if posting the code is going to help. I guess that there is a relationship at fault in the entity so I'm looking into that. </p>