title: the hibernate-envers with liquibase
body: <p>My question can be trival, but documentation for hibernate-envers say I need just 2 steps to make hibernate envers work:</p>
  
  <ol>
  <li><p>the hibernate-envers jar on the classpath,</p></li>
  <li><p>an @Audited annotation on the entity.</p></li>
  </ol>
  
  <p>First of all I added:</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
      &lt;artifactId&gt;hibernate-envers&lt;/artifactId&gt;
      &lt;version&gt;5.2.12.Final&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>Second I added @Audited annotation above my entity:</p>
  
  <pre><code>@Entity
  @Audited
  @Table(name = "users")
  public class User {...}
  </code></pre>
  
  <p>After those 2 steps I've got an option to:</p>
  
  <ol>
  <li><p>generate auto schema using the hbm2ddl tool</p></li>
  <li><p>create the schema alone.</p></li>
  </ol>
  
  <p>A lot of ppl in tutorials/docs etc. says that you should do it alone so this is how my schema looks like (in thymeleaf).</p>
  
  <p>To make schema manually I had to create changeset with one special table (usually called revinfo):</p>
  
  <pre><code>    &lt;createTable tableName="revinfo"&gt;
          &lt;column name="rev" type="integer"&gt;
              &lt;constraints primaryKey="true"/&gt;
          &lt;/column&gt;
          &lt;column name="revtstmp" type="bigint"&gt;&lt;/column&gt;
      &lt;/createTable&gt;
  </code></pre>
  
  <p>Now I just need to add new tables called tablename_AUD (ofc I can change this name by adding new annotation in my entity @AuditTable("new_name"), but it's not the case) with added rev and revtype column.</p>
  
  <p>This is one of my existing tables in liquibase:</p>
  
  <pre><code>    &lt;createTable tableName="users"&gt;
          &lt;column name="id" type="int"&gt;
              &lt;constraints primaryKey="true" nullable="false"/&gt;
          &lt;/column&gt;
          &lt;column name="email" type="varchar(200)"&gt;
              &lt;constraints unique="true" nullable="false"/&gt;
          &lt;/column&gt;
          &lt;column name="first_name" type="varchar(60)"&gt;
              &lt;constraints nullable="false"/&gt;
          &lt;/column&gt;
          &lt;column name="last_name" type="varchar(60)"&gt;
              &lt;constraints nullable="false"/&gt;
          &lt;/column&gt;
      &lt;/createTable&gt;
  </code></pre>
  
  <p>So this is how my users_AUD looks like:</p>
  
  <pre><code>    &lt;createTable tableName="users_AUD"&gt;
          &lt;column name="id" type="bigint"&gt;
              &lt;constraints primaryKey="true" nullable="false"/&gt;
          &lt;/column&gt;
          &lt;column name="rev" type="bigint"&gt;
              &lt;constraints referencedTableName="revinfo"
                           foreignKeyName="fk_users_AUD_revinfo"
                           referencedColumnNames="rev"
                           nullable="false"/&gt;
          &lt;/column&gt;
          &lt;column name="revtype" type="smallint"/&gt;
          &lt;column name="email" type="varchar(200)"&gt;
              &lt;constraints unique="true" nullable="false"/&gt;
          &lt;/column&gt;
          &lt;column name="first_name" type="varchar(60)"&gt;
              &lt;constraints nullable="false"/&gt;
          &lt;/column&gt;
          &lt;column name="last_name" type="varchar(60)"&gt;
              &lt;constraints nullable="false"/&gt;
          &lt;/column&gt;
      &lt;/createTable&gt;
  </code></pre>
  
  <p>The question is: Why I have an ERROR:</p>
  
  <blockquote>
    <p>org.springframework.beans.factory.BeanCreationException: Error
    creating bean with name 'entityManagerFactory' defined in class path
    resource
    [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]:
    Invocation of init method failed; nested exception is
    java.lang.NoClassDefFoundError:
    org/hibernate/boot/registry/classloading/internal/ClassLoaderServiceImpl$Work</p>
  </blockquote>
  
  <p>I added also entity manager depedency in my pom, but it didnt solve my problem. </p>
  
  <p>Earlier called:</p>
  
  <blockquote>
    <p>Such mapping is possible, but has to be explicitly defined using
    @Audited(targetAuditMode = NOT_AUDITED)</p>
  </blockquote>
  
  <p>And answer from @ThomasEdwin helped me out. He said that we need to</p>
  
  <pre><code>add @Audited to all related entities.
  </code></pre>
  
  <p>Or like I noticed we can also annotate in our entity</p>
  
  <pre><code>@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED).
  </code></pre>
  
  <p>A lot of similar questions are out-of-date (earlier there was much more needed to configure/set up envers, thats why I created new question).</p>
  
  <p>update:
  After fixes with versions etc. finally app runs, but when I try to add an user by a POST I've got error like this:</p>
  
  <p><a href="https://pastebin.com/raw/d1vqY6xp" rel="nofollow noreferrer">https://pastebin.com/raw/d1vqY6xp</a></p>