i’m facing following error when starting up the application with Oracle database, this happens after upgraded the spring from 2.x to 3.x, which upgraded the hibernate from 5.x to 6.x.
2024-05-08 16:49:43,551 +08:00 ERROR LocalContainerEntityManagerFactoryBean [main] - Failed to initialize JPA EntityManagerFactory: [PersistenceUnit: fooBar] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not instantiate id generator [entity-name=x.y.z.Foo]
Following is my entity class structure
@Entity
public class Foo implements Serializable
{
@Id
@SequenceGenerator(name = "FooSeqGenerator", sequenceName = "Foo_Seq")
@GeneratedValue(strategy = GenerationType.AUTO, generator = "FooSeqGenerator")
private int id;
private String name;
}
Following is my sequence
CREATE SEQUENCE Foo_Seq INCREMENT BY 1 MINVALUE 1 MAXVALUE 9999999999999999999999999999 NOCYCLE CACHE 20 NOORDER
This problem resolved after i overrided the allocationSize attribute in SequenceGenerator annotation as follows
@SequenceGenerator(name = "FooSeqGenerator", sequenceName = "Foo_Seq", allocationSize = 1)
But i don’t understand why this error occurred & why this change fixed the problem. Can anyone explain this? Or what should i do to fix this problem? Thanks.