Justin.Bell Justin.Bell - 11 months ago 74
Java Question

H2 Integration Test Database not following the same naming as MySQL prod DB

I've been working on writing some integration tests that use an in memory (H2) database, but I'm stuck on this error.

Caused by: org.h2.jdbc.JdbcSQLException: Table "TESTTABLE" not found; SQL statement:

The issue is, that in production Hibernate is changing both table names and column names from camel casing to underscores. (TestTable -> test_table) but with the H2 test DB it is just going to uppercase (TestTable -> TESTTABLE)

Here is my test config class:

@EnableJpaRepositories(basePackageClasses = {
public class InMemoryDataConfig {

public DataSource dataSource() {
return new EmbeddedDatabaseBuilder()

public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setPackagesToScan(new String[]{"org.test.domain.entity"});

JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();

return em;

protected Properties buildHibernateProperties() {
Properties hibernateProperties = new Properties();

hibernateProperties.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
hibernateProperties.setProperty("hibernate.show_sql", "true");
hibernateProperties.setProperty("hibernate.use_sql_comments", "true");
hibernateProperties.setProperty("hibernate.format_sql", "true");

return hibernateProperties;

public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
JpaTransactionManager transactionManager = new JpaTransactionManager();
return transactionManager;

public TestService testService() {
return new TestService();


I would rather not have to annotate everything just so the tests can know what the names are.

Any thoughts or suggestions on fixing this? Thanks for any help!

Answer Source

This doesn't quite answer the specific question I asked, but I was able to get it working in a much more simple way. If you scrap everything I had posted in my original question you just need to do a couple things.

First you must include the dependency. I'm using gradle so I just added this:


Next, add these annotations to your test:

public class MultifamilyIntegrationTest {

    protected TestService testService;

    public void test() {


Last, you must include a data.sql and a schema.sql file inside your /src/test/resources folder.

The schema.sql file is a creation script for everything schema related.

The data.sql file is to insert all of the needed data.