Every developer has those moments where a seemingly simple task turns into a head-scratching puzzle. This error, encountered while trying to configure a custom LocalSessionFactoryBean in Spring Boot, is a perfect example of a subtle type mismatch causing a cryptic failure.
The Scenario and the Error
The goal was to set up a custom SessionFactory bean using Spring’s LocalSessionFactoryBean. The initial, problematic configuration was:
@Configuration
public class HibernateConfig {
@Bean
public LocalSessionFactoryBean sessionFactory() {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
// … set data source, hibernate properties …
// This line caused the error!
sessionFactory.setConfigurationClass(org.hibernate.cfg.Configuration.class);
return sessionFactory;
}
}
This configuration resulted in the following exception upon application startup:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory':
Bean property 'configurationClass' is not writable or has an invalid setter method.
Does the parameter type of the setter match the return type of the getter?
Continue reading Solved: Bean property ‘configurationClass’ is not writable or has an invalid setter method