AutoIncrement Id PostgreSQL et Spring Boot Data JPA

Je ne parviens pas à créer un nouvel enregistrement dans ma firebase database PostgreSQL. Je veux juste poster au service REST un nouvel utilisateur (int: id, Ssortingng: email, Ssortingng: mot de passe), mais j’ai cette erreur:

"exception": "org.springframework.dao.DataIntegrityViolationException", "message": "could not execute statement; SQL [n/a]; constraint [id]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement 

Ce sont mes classes Java:

Domaine

 @Entity @Table(name = "users") public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; private Ssortingng email; private Ssortingng password; public User() {} public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public Ssortingng getEmail() { return email; } public void setEmail(Ssortingng email) { this.email = email; } public Ssortingng getPassword() { return password; } public void setPassword(Ssortingng password) { this.password = password; } } 

Manette

 @RestController @RequestMapping("/users") public class UserController { @Autowired private UserService userService; @RequestMapping(method = RequestMethod.GET) public List findAll() { return userService.findAll(); } @RequestMapping(method = RequestMethod.POST) public User addUser(@RequestBody User user) { userService.addUser(user); return user; } } 

Un service

 @Service public class UserService { @Autowired private UserRepository userRepository; public List findAll() { return (List) userRepository.findAll(); } public User addUser(User user) { userRepository.save(user); return user; } } 

Dépôt

 public interface UserRepository extends CrudRepository { // TODO } 

SQL

 CREATE TABLE users( id INT PRIMARY KEY NOT NULL, email TEXT NOT NULL, password CHAR(20) NOT NULL ); 

S’il vous plaît, aidez-moi, car je ne sais pas comment aborder ce problème.

J’ai trouvé la solution. J’ai besoin de changer le script pour ces derniers:

 CREATE TABLE users( id SERIAL PRIMARY KEY NOT NULL, email TEXT NOT NULL, password TEXT NOT NULL ); 

Ensuite, l’entité devrait être annotée avec ceci:

 @Entity @Table(name = "users") public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(columnDefinition = "serial") private Long id; private Ssortingng email; private Ssortingng password; public User() {} public Long getId() { return id; } public void setId(Long id) { this.id = id; } public Ssortingng getEmail() { return email; } public void setEmail(Ssortingng email) { this.email = email; } public Ssortingng getPassword() { return password; } public void setPassword(Ssortingng password) { this.password = password; } } 

SQL devrait être comme ça ..

 CREATE TABLE users( id INT PRIMARY KEY BIGINT NOT NULL AUTO_INCREMENT, email TEXT NOT NULL, password CHAR(20) NOT NULL );