0

I use last H2 (current master) and Hibernate 5.14.14 as JPA provider. I have the following column in table:

ID INT NOT NULL AUTO_INCREMENT

and the following field in entity:

@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;

And this is my code:

//POINT A entity.getId() = null
entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
entityManager.persist(entity);
entityManager.getTransaction().commit();
//POINT B entity.getId() = null.

My question - at point B according to JPA specification entity.getId() must return the value that database (H2) generated for this column (I mean next ID for the row) or null? I need to know, why I have null at point B - is the problem in H2/Hibernate or in my understanding of JPA.

Pavel_K
  • 10,748
  • 13
  • 73
  • 186

0 Answers0