spring Hibernate Jpa错误:“java.sql.SQLSyntaxErrorException:表不存在”

y1aodyip  于 11个月前  发布在  Spring
关注(0)|答案(1)|浏览(148)

不知何故,我得到了引起:java.sql.SQLSyntaxErrorException:表'zahnmobil.worker_table' doesn 't exist.我已经尝试了一切,我发现无处不在,但没有工作.帮助将不胜感激!!我的Pom.xml文件依赖:

<description>Mobile Zahnarzt System.</description>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>

        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <scope>runtime</scope>
        </dependency>
        
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>com.adesso.zahnmobil.web</groupId>
            <artifactId>web-generated</artifactId>
            <version>1.0.0</version>
        </dependency>
           

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>
    
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>test</scope>
        </dependency>

字符串
我的简历:

package com.adesso.zahnmobil.model;

import java.util.UUID;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import org.springframework.transaction.annotation.Transactional;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Entity
@Table(name="worker_table")

public class Worker {
  @Id
  private String id = UUID.randomUUID().toString();

  @Column(name= "name")
  private String name;
}


存储库:

package com.adesso.zahnmobil.repository;

import org.springframework.data.jpa.repository.JpaRepository;

import com.adesso.zahnmobil.model.Worker;
public interface WorkerRepository extends JpaRepository<Worker, String> {
    
}


应用程序.yml文件

server:
  hostname: ${SERVER_HOSTNAME:http://localhost:4200}
  forward-headers-strategy: native
  servlet:
    session:
      cookie:
        http-only: true
        secure: true

  error:
    include-message: always
    include-binding-errors: always

spring:
  datasource:
    username: root
    password: password
    url: jdbc:mysql://${DATABASE_HOST:localhost}:${SQL_PORT:3306}/${DATABASE_NAME:zahnmobil}?createDatabaseIfNotExist=true&useSSL=false

testDatabase:
  enabled: ${DATABASE_POPULATE_WITH_TESTOBJECTS:true}

jpa:
  database-platform: ${SQL_DIALECT:org.hibernate.dialect.MySQL8Dialect}
  generate-ddl: true
  hibernate:
    ddl-auto: ${SQL_DDL_AUTO:create-drop}
  show-sql: true


我的Springboot应用程序文件

package com.adesso.zahnmobil;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;

@SpringBootApplication
@EntityScan("com.adesso.zahnmobil.model") 
public class ZahnmobilApplication {

    public static void main(String[] args) {
        SpringApplication.run(ZahnmobilApplication.class, args);
    }

}


我完全迷路了。我试过自动扫描,但它仍然不起作用。我真的不知道该怎么办,因为我已经尝试了我在互联网上找到的一切

aor9mmx1

aor9mmx11#

根据您的pom,我假设您使用的是最新版本的Sping Boot ,即3。因此,请记住Sping Boot 2和3之间发生的主要变化之一是将包从javax迁移到jakaltar。这意味着您的项目中的所有导入都应该使用jakaltar而不是javax。就像在您的实体中一样,

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

字符串
你应该

import jakarta.persistence.*;


我还看到你出于某种原因添加了很多重复的依赖项,就像上一个一样。

<dependency> //you already have starter test defined on top
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
    </dependency>

    <dependency> //do you need security for current debugging task?
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>

    <dependency> //do you need security for current debugging task?
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-config</artifactId>
    </dependency>

    <dependency> //core is already included in the starter
        <groupId>org.springframework.security</groupId>
        <artifactId>spring-security-core</artifactId>
    </dependency>

    <dependency> //you already defined jpa on top
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
    </dependency>

     <dependency> //you already have mysql dependency
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>test</scope>
    </dependency>


如果您只是在创建一个项目,请尝试将依赖关系保持在最低限度,直到您解决当前的问题,例如

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
    <groupId>com.mysql</groupId>
    <artifactId>mysql-connector-j</artifactId>
    <scope>runtime</scope>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <optional>true</optional>
</dependency>


为了使更改可见,您需要在IDE中执行Maven > Update / Reload
在你解决了这个问题之后,你可以继续添加你需要的依赖项,但是我坚信jakerimports会解决这个问题。

相关问题