11

I am using Hibernate Envers with entity

@Entity
@Table(name = "users", schema = "core")
@Audited public class Users implements java.io.Serializable, Comparable<Users> {
    protected static final long serialVersionUID = 1250157348010696249L;    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "userid")
    protected Integer userId;

    @Column(name = "aduserid")
    protected String aduserId;

    @Column(name = "firstname")
    protected String firstName;

    @Column(name = "middlename")

i am getting error hibernate sequence does not exist .

when i am changing false then it says revision generator does not exist. Pls help me.

Ritesh
  • 7,472
  • 2
  • 39
  • 43
user3460330
  • 165
  • 3
  • 11
  • Please format your question properbly – Jens Nov 12 '15 at 14:27
  • Use a hbm2ddl export, create the script and check the `CREATE` statements have been run on your database. Maybe just use the script as-is in a fresh empty database ? http://stackoverflow.com/questions/438146/hibernate-hbm2ddl-auto-possible-values-and-what-they-do ... you probably need the hibernate_sequence table that will get created in the script if it is needed. What database you use? – Darryl Miles Nov 12 '15 at 14:30
  • 1
    Was the issue identified? Could you please post your fix? I am evaluating using hibernate-envers and having this same issue when I add the @Audited annotation to the entity class. – SGB Oct 24 '16 at 17:00

3 Answers3

12

you need to create hibernate_sequence in your database, check sample code

CREATE SEQUENCE hibernate_sequence  INCREMENT 1  MINVALUE 1
  MAXVALUE 9223372036854775807
  START 1
  CACHE 1;
Sangram Badi
  • 4,054
  • 9
  • 45
  • 78
  • Is this the case with every DB ? I remember using envers with an SQL Server DB and there I created no explicit sequence (or I am not able to find it in the project's code). – Tchypp Jul 26 '21 at 06:59
  • It worked. But I couldn't find any documentation indicating that we must create this sequence. Also, even if we set `spring.jpa.hibernate.ddl-auto = create`, hibernate won't generate the sequence. – Hossein Nasr Feb 15 '23 at 04:54
4

Hibernate Envers expects a global sequence "hibernate_sequence" in order to insert into the "revinfo" table.

Jean-Christophe
  • 624
  • 5
  • 11
0

I solved this by creating a custom entity for the revision info:

@Entity
@RevisionEntity
@Table(name="_revinfo")
public class RevInfoEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @RevisionNumber
    @Column(name="rev")
    private long rev;

    @RevisionTimestamp
    @Column(name="revtstmp")
    private LocalDateTime revtstmp;
}

The table and column names maybe have to be adjusted.

Patrick
  • 264
  • 2
  • 8