Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring with embedded derby: hibernate dialect deprecation

I have a spring application configured with spring boot and config annotations.

JPA configuration is:

@Configuration
@EnableTransactionManagement
@EnableJpaRepositories
public class JpaConfiguration {

    @Bean
    public DataSource dataSource() {
        return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.DERBY).build();
    }

    @Bean
    public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource,
            JpaVendorAdapter jpaVendorAdapter) {
        LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean();
        lef.setDataSource(dataSource);
        lef.setJpaVendorAdapter(jpaVendorAdapter);
        lef.setPackagesToScan( /* "..." */ );
        return lef;
    }

    @Bean
    public JpaVendorAdapter jpaVendorAdapter() {
        HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter();
        hibernateJpaVendorAdapter.setShowSql(true);
        hibernateJpaVendorAdapter.setGenerateDdl(true);
        hibernateJpaVendorAdapter.setDatabase(Database.DERBY);
        return hibernateJpaVendorAdapter;
    }

    @Bean
    public PlatformTransactionManager transactionManager() {
        return new JpaTransactionManager();
    }
}

I consistently get in the logs:

[...]
HHH000400: Using dialect: org.hibernate.dialect.DerbyDialect
HHH000430: The DerbyDialect dialect has been deprecated; use one of the version-specific dialects instead
[...]

I tried adding:

@Bean
public DerbyTenSevenDialect jpaDialect() {
    return new DerbyTenSevenDialect();
}

but then the returned bean is not compatible with:

LocalContainerEntityManagerFactoryBean lef //.....
lef.setJpaDialect(JpaDialect);

How do I get rid of the deprecation warning?

like image 624
guido Avatar asked Mar 30 '14 08:03

guido


1 Answers

Just ditch the following line totally (without replacing it with anything else):

hibernateJpaVendorAdapter.setDatabase(Database.DERBY);

That's all I did and Hibernate correctly logged:

Using dialect: org.hibernate.dialect.DerbyTenSevenDialect

After that there is no need of manually defining the Dialect Bean. Hibernate figures out the correct dialect on it's own

like image 193
geoand Avatar answered Oct 18 '22 22:10

geoand