0

I am getting "ERROR: relation "hibernate_sequence" does not exist" exception while doing insert operation.

Technical Stack

-> Springboot
-> Hibernate
-> PostgreSQL


Approaches tried so far.

-> Verified all entity classes in project, generation strategy is used as "@GeneratedValue(strategy = GenerationType.IDENTITY)".

-> Verified database tables, pk is either Serial or Int with proper sequence generated value.

-> Tried with use-new-id-generator-mappings property as false, didn't worked.

-> Verified sequence with name "hibernate_sequence" is available in Database.

Analysis so far

-> Entities those are annotated with @Audited having this issue as hibernate envers expect global "hibernate_sequence". But not able to find the exact solution.

Note : This was working few days back without any issue, Since last week started getting this issue.
Aditya
  • 145
  • 1
  • 1
  • 5
  • May be this can solve your problem:- https://stackoverflow.com/questions/32968527/hibernate-sequence-doesnt-exist –  Jan 13 '22 at 03:56

2 Answers2

0

As you said, hibernate-envers is looking for the hibernate_sequence.

Its used to insert records into the REVINFO table

Assuming spring.jpa.hibernate.ddl-auto is not set to create

either

  1. create a hibernate_sequence manually
  2. create a sequence with the name you want. e.g rev_id_seq. Then override the REVINFO definition to change the sequence name by adding your definition of the RevisionEntity
@Entity
@RevisionEntity
public class MyRevision implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "rev_id_generator")
    @SequenceGenerator(name = "rev_id_generator", sequenceName = "rev_id_seq", allocationSize = 1)
    @RevisionNumber
    private int id;

    @RevisionTimestamp
    private long timestamp;

    // Getters, setters, equals, hashCode ...
}

https://docs.jboss.org/hibernate/orm/current/userguide/html_single/Hibernate_User_Guide.html#envers-tracking-modified-entities-revchanges

https://thorben-janssen.com/hibernate-envers-extend-standard-revision/

indybee
  • 1,321
  • 11
  • 12
0

Initially set the spring.jpa.hibernate.ddl-auto to create for the first time and run the application. It will create the hibernate sequence. after that change spring.jpa.hibernate.ddl-auto to none. It will prevent any further data loss from tables. Or you can set to update if necessary.

Fahim Fahad
  • 61
  • 1
  • 2
  • 4