13

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.

3
  • Please format your question properbly Commented Nov 12, 2015 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 ? stackoverflow.com/questions/438146/… ... you probably need the hibernate_sequence table that will get created in the script if it is needed. What database you use? Commented Nov 12, 2015 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. Commented Oct 24, 2016 at 17:00

3 Answers 3

13

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;
Sign up to request clarification or add additional context in comments.

2 Comments

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).
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.
4

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

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.