Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sequence "HIBERNATE_SEQUENCE" not found; SQL statement

In my spring mvc app, i have the following object. I am trying to make a visual of data using devtool in my app.

@Entity @Data public class ConsultationRequest {     @Id     @GeneratedValue     private Long id;      private String name;      private String email;      private String purpose;      private String programme;      private int year;      private String language;      private String comments;     @Enumerated(EnumType.STRING)     private ConsultationStatus status; } 

Then i used the jpa to make the entity:

@Repository public interface ConsultationRequestRepository extends JpaRepository<ConsultationRequest, Long> {  } 

The problem is when i load my application, i face with 2 errors:

 Unsuccessful: drop sequence hibernate_sequence [36morg.hibernate.tool.hbm2ddl.SchemaExport  Sequence "HIBERNATE_SEQUENCE" not found; SQL statement: 

Then when i open the

http://localhost:8080/h2-console/ 

I cannot see the table. It seems that the in the boot process, table is not made.

like image 209
Jeff Avatar asked Oct 01 '16 13:10

Jeff


People also ask

What is the default sequence table name in hibernate?

As you have not specified a sequence table name, hibernate will look for a sequence table named as hibernate_sequence and use it as default. For Oracle/Postgres, increment fields used are sequence tables. In MySql, there are increment fields that automatically increment.

How to get the next identity value in a hibernate sequence?

Hibernate is trying to get the next identity value by executing select nextval ('hibernate_sequence'). I would suspect there is no sequence called hibernate_sequencein your db, and you need to define one. Don't know how this works using Postgre however

Does hibernate start with 1 increment by 1 statement?

Hibernate: create sequence hibernate_sequence start with 1 increment by 1statement appears in the log, whilst I have initialized the database with two records already. After this if it doesn’t catch the current state it can do anything (it does increment though), but it gets a wrong value. Thanks for your helps! Regards, Bálint

Why is my hibernate_sequence not increasing?

Which actually means that after correctly invoking the included sql script, the hibernate_sequence does not get incremented - it starts at 1. It means the SQL script did not use the sequence, or you told Hibernate to recreate the schema, therefore discarding anything the script did.


1 Answers

Update your code as below:

 @Id  @GeneratedValue(strategy = GenerationType.IDENTITY)  private Long id; 

As you have not specified a sequence table name, hibernate will look for a sequence table named as hibernate_sequence and use it as default.

For Oracle/Postgres, increment fields used are sequence tables.
In MySql, there are increment fields that automatically increment.

like image 143
Rohit Gaikwad Avatar answered Sep 19 '22 03:09

Rohit Gaikwad