My entity has a mapOrder field which I want 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 good:
CREATE TABLE map
(
id bigserial NOT NULL,
map_order serial NOT NULL,
...
)
But when I save it with Spring Data JPA's repository, like this:
Map m=new Map();
repo.save(m);
will give me exception:
Caused by: org.postgresql.util.PSQLException: ERROR: null value in column "map_order" violates not-null constraint
Any ideas?