I am experiencing problem with Hibernate throwing following error:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'Library.book' doesn't exist
My dependency setup looks like this (I believe this might be the reason):
compile("org.springframework.boot:spring-boot-starter-web")
testCompile("org.springframework.boot:spring-boot-starter-test")
compile 'org.springframework:spring-orm:4.1.6.RELEASE'
compile 'org.springframework.data:spring-data-jpa:1.8.0.RELEASE'
compile 'org.hibernate:hibernate-entitymanager:4.3.8.Final'
compile 'org.hibernate:hibernate-core:4.3.8.Final'
compile 'org.apache.commons:commons-dbcp2:2.1'
compile 'mysql:mysql-connector-java:5.1.35'
compile 'org.apache.logging.log4j:log4j-core:2.2'
So I am using spring-boot-starter-web (project created using Spring CLI), then added not-spring-boot dependencies for Hibernate and Spring Data among other things (used the exact same dependency set in different projects, but without spring-boot-starter-web and everything worked just fine).
After reading others' questions I checked whether my @EnableJpaRepositories has correct path to Repositories and if entityManagerFactoryBean has packagesToScan set correctly.
I believe that Spring Boot has conflicts with other dependencies, because my configuration looks fine.
I will now show some code snippets, because I might be wrong about my configuration's correctness ;p
Book MySQL DDL:
CREATE TABLE IF NOT EXISTS `Library`.`Book` (
`id` INT NOT NULL AUTO_INCREMENT,
`title` VARCHAR(100) NOT NULL,
`description` VARCHAR(256),
`genre` VARCHAR(50) NOT NULL,
`releaseDate` DATE NOT NULL,
PRIMARY KEY (`id`)
)
Book entity:
@Entity
@Table(name="Book")
public class Book {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String title;
private String description;
private String genre;
@Temporal(TemporalType.DATE)
private Date releaseDate;
}
EntityManagerFactory bean:
@Bean
@Autowired(required = true)
public EntityManagerFactory entityManagerFactory(DataSource dataSource) {
HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
vendorAdapter.setGenerateDdl(true);
vendorAdapter.setShowSql(false);
vendorAdapter.setDatabasePlatform("org.hibernate.dialect.MySQLDialect");
vendorAdapter.setDatabase(Database.MYSQL);
LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean();
factory.setJpaVendorAdapter(vendorAdapter);
factory.setPackagesToScan("pl.com.imralav.library.data.entity");
factory.setDataSource(dataSource);
Properties properties = new Properties();
properties.setProperty("hibernate.generate_statistics", "false");
properties.setProperty("hibernate.show_sql", "false");
factory.setJpaProperties(properties);
factory.afterPropertiesSet();
return factory.getObject();
}
Please tell me if you need more information.