I am encountering an error when running my Spring Boot application with Hibernate 6.4.4.Final. The application fails to start due to a BeanCreationException
caused by a duplicate annotation in Hibernate’s bytecode enhancement.
Error Details:
Application run failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in com.example.persistence.config.SchemaDataSourceConfig: Duplicate annotation for class interface org.hibernate.bytecode.enhance.spi.EnhancementInfo (versions 6.4.4.Final")
2024-07-11 05:43:37,676 ERROR [main] [trace id: span id: [org.springframework.boot.SpringApplication)] Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in com.example.persistence.config.SchemaDataSourceConfig: Duplicate annotation for class: org.hibernate.bytecode.enhance.spi.EnhancementInfo (version="6.4.4.Final") interface org.hibernate.bytecode.enhance.spi.EnhancementInfo
Caused by: java.lang.annotation.AnnotationFormatError: Duplicate annotation for class interface org.hibernate.bytecode.enhance.spi.EnhancementInfo (version 6.4.4.Final")
at java.base/sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:126)
at java.base/sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:73)
at java.base/java.lang.Class.createAnnotationData(Class.java:4246)
at java.base/java.lang.Class.annotationData(Class.java:4235)
at java.base/java.lang.Class.annotationData(Class.java:4251)
at java.base/java.lang.Class.isAnnotationPresent(Class.java:4128)
at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.<init>(AnnotationMetadataSourceProcessorImpl.java:204)
...
@Primary
@DependsOn({"dataSource"})
@Qualifier("entityManagerFactory")
@Bean(name = {"entityManagerFactory"})
public LocalContainerEntityManagerFactoryBean entityManagerFactory(@Qualifier("dataSource") DataSource dataSource) {
LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean();
entityManagerFactory.setPersistenceUnitName("my_schema");
AbstractJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter();
jpaVendorAdapter.setShowSql(false);
jpaVendorAdapter.setDatabase(Database.MYSQL);
jpaVendorAdapter.setDatabasePlatform("org.hibernate.dialect.MySQLDialect");
entityManagerFactory.setJpaVendorAdapter(jpaVendorAdapter);
entityManagerFactory.setJpaDialect(new HibernateJpaDialect());
entityManagerFactory.setDataSource(dataSource);
entityManagerFactory.setPackagesToScan(new String[]{"com.example", "com.anotherpackage"});
entityManagerFactory.setJpaProperties(this.mySchemaHibernateProperties());
return entityManagerFactory;
}
private Properties mySchemaHibernateProperties() {
// Properties implementation
}