title: Envers queries use wrong column names for _MOD columns
body: <p>I am using Hibernate Envers with the <code>@Audited( withModifiedFlag=true )</code> and I have a problem where the SQL generated for queries has different column names than the one generated by the <code>HBM2DDL</code> tool for the <code>_MOD</code> columns</p>
  
  <p>The issue might have something to do with the fact that I am overriding the Hibernate naming strategy as described <a href="https://stackoverflow.com/a/10594354/11758992">here</a>. But trying to debug this, I have had no luck in verifying this theory - the naming strategy does not seem to hit any breakpoints.</p>
  
  <p>The entity looks like this (with irrelevant properties omitted):</p>
  
  <pre class="lang-java prettyprint-override"><code>@Entity
  @Table(name = "file")
  @Audited(withModifiedFlag = true)
  public class FileEntity {
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private long id;
  
      @Column(name = "file_name")
      private String fileName;
  }
  </code></pre>
  
  <p>The generated <code>_AUD</code> table looks like this:</p>
  
  <pre class="lang-sql prettyprint-override"><code>CREATE TABLE file_AUD (
      id int8 NOT NULL,
      REV int4 NOT NULL,
      REVTYPE int2,
      REVEND int4,
      file_name varchar(255),
      fileName_MOD boolean,
      PRIMARY KEY (id, REV)
  );
  </code></pre>
  
  <p>I can see the difference between the <code>file_name</code> and <code>fileName_MOD</code> columns, but that seems to be expected, as described <a href="https://hibernate.atlassian.net/browse/HHH-10398" rel="nofollow noreferrer">here</a></p>
  
  <p>When making a change to the entity or when using the <code>AuditReaderFactory</code> for a query, the following SQL error is shown:</p>
  
  <pre><code>ERROR: column fileentity0_.file_name_mod does not exist
    Hint: Perhaps you meant to reference the column "fileentity0_.filename_mod".
  </code></pre>
  
  <p>I am using PostgreSQL and Hibernate <code>5.2.13.Final</code>
  I understand there is a workaround with using the <code>modifiedColumnName</code> on each property, but the example above is just one of many entities I am trying to audit, so I am looking for other solutions.</p>
  
  <p>EDIT:</p>
  
  <p>Digging a bit deeper into the NamingStrategy, it seems the code was not actually using the custom one I had added. It seems the Hibernate <code>naming_strategy</code> property was split into <code>implicit_naming_strategy</code> and <code>physical_naming_strategy</code> and this seems to have went unnoticed as the version of Hibernate in the project was updated.
  Instead, these properties are provided by Spring JPA by default as follows:</p>
  
  <pre><code>hibernate.implicit_naming_strategy:org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
  hibernate.physical_naming_strategy:org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
  </code></pre>
  
  <p>Since they do the job (outside of this Envers issue), I will not be using the custom one.</p>
  
  <p>An example of a query I use:</p>
  
  <pre class="lang-java prettyprint-override"><code>AuditReader auditReader = AuditReaderFactory.get(entityManager);
  
  AuditQuery auditQuery = auditReader.createQuery()
          .forRevisionsOfEntity(FileEntity.class, false, true)
          .addOrder(AuditEntity.revisionNumber().desc())
          .setFirstResult((int) pageable.getOffset())
          .setMaxResults(pageable.getPageSize());
  </code></pre>