Peter Delaney
Peter Delaney

Reputation: 5388

springboot + JPA + MySql + Entity table generated uppercase

Have an issue where in SpringBoot 2.1.4 JPA using Hibernate to MySql is producing uppercase table names and I keep getting error that table not recognized for CONTENTSET. Real table name in MySql is lowercase contentset.

The sql that is produced from the log file looks good, but my test keeps error out complaining about the UPPERCASE table name. This is MySql database to table names are case sensitive.

Here is the logging information text

Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "CONTENTSET" not found; SQL statement:
select contentset0_.contentsetid as contents1_1_, contentset0_.checksum as checksum2_1_, contentset0_.contentsetname as contents3_1_, contentset0_.zipped as zipped4_1_ from contentset contentset0_ [42102-199]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:451)
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:427)
    at org.h2.message.DbException.get(DbException.java:205)

Entity Bean

@Entity
@Table(name = "contentset")
public class ContentSet implements Serializable {

    @Id
    @Column(name="CONTENTSETID")
    private String contentSetId;

    @Column(name="CONTENTSETNAME", nullable=false)
    private String contentSetName;
    ......

ContentSetRepository.java file

public interface ContentSetRepository extends JpaRepository<ContentSet, String> { }

my application.properties test

spring.datasource.url=jdbc:mysql://10.80.100.62:3306/receiver
spring.datasource.username=xxx
spring.datasource.password=xxx
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.database = MYSQL
spring.jpa.show-sql = true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.hibernate.ddl-auto = none
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect

# NOTHING SEEMS TO RESOLVE UPPERCASE TABLE name
#spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl
#spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

My Test that keeps failing

@RunWith(SpringRunner.class)
@DataJpaTest
@AutoConfigureTestDatabase(replace=AutoConfigureTestDatabase.Replace.AUTO_CONFIGURED)  
@TestPropertySource(locations = "classpath:application.properties")
public class ContentSetRepositoryMySqlTest {

    @Autowired private ContentSetRepository contentSetRepo;

    @Test
    public void testFindAll_For_ContentSetRepository() {
        Assertions.assertThat(contentSetRepo).isNotNull();

        try {
            Collection<ContentSet> all = contentSetRepo.findAll();
            Assertions.assertThat(all).isNotNull();
            Assertions.assertThat(all.size()).isGreaterThan(0);
        } catch(Exception ex ) {
            ex.printStackTrace();
            Assertions.fail("Exception : " + ex.getMessage());
        }
    }
}

Upvotes: 1

Views: 2065

Answers (1)

sam
sam

Reputation: 2004

Maybe you have included H2 database dependency in your pom.xml or you might have beans that has something to do with H2 database and so the error says:

Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "CONTENTSET" not found; SQL statement:

Table names and Column names are case sensitive in H2 but not in MySQL. Could you update the question with the content of your pom.xml.

Upvotes: 1

Related Questions