Spring JPA data "null in column xxx violates non-null constraint" in sequential column with postgresql
My entity has a mapOrder field that I want to auto-increment like below:
@Entity
public class Map{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(columnDefinition = "serial")
private Long mapOrder;
//.......
}
The sql generated seems to be good:
CREATE TABLE map
(
id bigserial NOT NULL,
map_order serial NOT NULL,
...
)
But when I save it with Spring Data JPA datastore like:
Map m=new Map();
repo.save(m);
will give me an exception:
Caused by: org.postgresql.util.PSQLException: ERROR: null value in column "map_order" violates not-null constraint
Any ideas?
+3
source to share