title: Hibernate Envers revision number order
body: <p>I used Envers to audit my entities. The DB used is Oracle 11g. For the revision number of the revision entity, I used a oracle sequence. But since the oracle sequence does not guarantee monotonic increasing of each call to nextval, In my revision table, I got something like this,<a href="https://i.stack.imgur.com/nqxE2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nqxE2.png" alt="enter image description here"></a></p>
  
  <p>We can see that the rev number is not monotonically increasing. In the audit table of my entity, I have this:</p>
  
  <p>By chaining the records together with the rev number to form a timeline, I got :</p>
  
  <p>24 --> 1302 --> 1303 <strong>--></strong> 1355 <strong>--></strong> 1304 --> 1356 --> 1357 --> 1305 -->1358 --> null</p>
  
  <p>In fact, I have a cluster of 2 servers. They both can persist data into the DB. I suspect that this has relation to the problem of order in revnumber. Because of this problem. Query like MyEntity anEntity = auditReader.find(MyEntity.class, id, revNum) doesn't work because of 
  <code>org.hibernate.envers.query.impl.AbstractAuditQuery.getSingleResult(AbstractAuditQuery.java:117)</code> . I checked the SQL generated by Hibernate, in the where clause</p>
  
  <pre><code> where
      myentity.rev&lt;=?
      and myentity.revtype&lt;&gt;?
      and myentity.id=?
      and (
          myentity.revend&gt;?
          or myentity.revend is null
      )
  </code></pre>
  
  <p>so for the rev number 1356, several audit records are retrieved, for example
  1356 --> 1357 and 1305 -->1358  because rev num 1356 is just between the two ends.</p>
  
  <p>How can I solve this problem? I mean to make the rev number monotonically increasing one transaction after another.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>My revision entity</p>
  
  <pre><code>@Entity
  @RevisionEntity(CustomRevisionListener.class)
  @Table(name = "REV_TABLE")
  @SequenceGenerator(name = "GENERIC_GENERATOR", sequenceName = "SQ_REVISION_ID")
  public class Revision {
      @Id
      @GeneratedValue(strategy = GenerationType.SEQUENCE, generator ="GENERIC_GENERATOR")
      @Column(nullable = false, name = REV)
      @RevisionNumber
      private long rev;
  
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/lm9ZI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lm9ZI.png" alt="enter image description here"></a></p>