Languages

Spring + Hibernate + H2 - error - h2 Caused by: org.h2.jdbc.JdbcSQLException: Sequence "HIBERNATE_SEQUENCE" not found; SQL statement:

6 points
Asked by:
Kate_C
21400

How to fix this error:

h2 Caused by: org.h2.jdbc.JdbcSQLException: Sequence "HIBERNATE_SEQUENCE" not found; SQL statement:

This error occurs when I try to save new entity with repository:

UserEntity user = new UserEntity("Tom", 25);
userRepository.save(user);

My entity:

import javax.persistence.*;
import java.util.Objects;

@Entity
@Table(name = "users")
public class UserEntity {

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

    private String name;
    private int age;

	// constructor
	// getters, setters
}

Repository:

import com.dirask.model.UserEntity;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface UserRepository extends CrudRepository<UserEntity, Long> {

}

 

1 answer
2 points
Answered by:
Kate_C
21400

Fix for this problem:

In UserEntity change:

@GeneratedValue(strategy = GenerationType.AUTO)

to:

@GeneratedValue(strategy = GenerationType.IDENTITY)

Entire entity fixed:

import javax.persistence.*;
import java.util.Objects;

@Entity
@Table(name = "users")
public class UserEntity {

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

    private String name;
    private int age;

	// constructor
	// getters, setters
}

 

0 comments Add comment
Native Advertising
­čÜÇ
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

ÔŁĄ´ŞĆ­čĺ╗ ­čÖé

Join