I've tried to use custom id-generator as in Bypass GeneratedValue in Hibernate (merge data not in db?) and it works fine while working with Postgres DB. My code is equals to the code in example. But while running test with H2 in-memory database I faced the problem, that id is not generated automaticaly.
Without custom generator
@Column(name = "id", nullable = false)
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
Generated create table script
create table db.schema.entity (id bigserial not null...
With custom generator
@Column(name = "id", nullable = false)
@Id
@GeneratedValue(generator = "idGenerator", strategy = GenerationType.IDENTITY)
@GenericGenerator(name="idGenerator", strategy = "...UseIdOrGenerate")
private Long id;
Generated create table script
create table db.schema.entity (id int8 not null...
As a result tests don't work.