小编Tom*_*mek的帖子

Hibernate说该表不存在,但确实存在

我遇到了Hibernate抛出以下错误的问题:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'Library.book' doesn't exist
Run Code Online (Sandbox Code Playgroud)

我的依赖项设置如下所示(我相信这可能是原因):

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'
Run Code Online (Sandbox Code Playgroud)

因此,我正在使用spring-boot-starter-web(使用Spring CLI创建的项目),然后为Hibernate和Spring Data添加了非spring-boot依赖关系(在不同项目中使用了完全相同的依赖关系集,但没有spring- boot-starter-web,一切正常。

阅读其他人的问题后,我检查了我的@EnableJpaRepositories是否具有正确的仓库路径,以及EntityManagerFactoryBean是否正确设置了packagesToScan。

我相信Spring Boot与其他依赖项存在冲突,因为我的配置看起来不错。

现在,我将显示一些代码片段,因为关于配置的正确性,我可能错了;

预订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`)
)
Run Code Online (Sandbox Code Playgroud)

图书实体:

@Entity
@Table(name="Book")
public class Book {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;
    private String title; …
Run Code Online (Sandbox Code Playgroud)

hibernate spring-data-jpa spring-boot

3
推荐指数
1
解决办法
6304
查看次数

标签 统计

hibernate ×1

spring-boot ×1

spring-data-jpa ×1