I'm not sure if this will help, but I continued to run into this message while searching for my answer, which I did not find anywhere, but found the solution myself. So I thought this might be the best place to share.
If you use hibernate as a JPA provider, you can manually call the identifier generator assigned to this entity class. First enter the JpaContext:
@Autowired org.springframework.data.jpa.repository.JpaContext jpaContext;
Then get the internal org.hibernate.id.IdentifierGenerator with this:
org.hibernate.engine.spi.SessionImplementor session = jpaContext.getEntityManagerByManagedType(MyEntity.class).unwrap(org.hibernate.engine.spi.SessionImplementor.class); org.hibernate.id.IdentifierGenerator generator = session.getEntityPersister(null, new MyEntity()).getIdentifierGenerator();
Now you can get the identifier from the generator programmatically:
Serializable id = generator.generate(session, new MyEntity());
Ty garside
source share