programing

스키마 'SA'가 존재하지 않으며 테이블을 삭제합니다.

kingscode 2023. 4. 1. 14:17
반응형

스키마 'SA'가 존재하지 않으며 테이블을 삭제합니다.

과정 및 주제 데이터베이스를 작성하기 위해 Spring Boot을 사용하고 있습니다.코스 클래스를 변경했을 때 나타나는 수많은 오류로 인해 어려움을 겪고 있습니다.뭐가 잘못됐는지 모르겠어요.다음은 오류 메시지입니다.

 ERROR 1136 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: alter table course drop constraint FKokaxyfpv8p583w8yspapfb2ar

    ERROR 1136 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Schema 'SA' does not exist

    ERROR 1136 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: drop table course

    ERROR 1136 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Schema 'SA' does not exist

    ERROR 1136 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : HHH000389: Unsuccessful: drop table topic

    ERROR 1136 --- [           main] org.hibernate.tool.hbm2ddl.SchemaExport  : Schema 'SA' does not exist

    WARN 1136 --- [           main] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Warning Code: 10000, SQLState: 01J01

    WARN 1136 --- [           main] o.h.engine.jdbc.spi.SqlExceptionHelper   :

데이터베이스 'memory:testdb'가 생성되지 않았습니다. 대신 기존 데이터베이스에 연결되었습니다.

그리고 여기 제 코스 코드입니다만, 토픽 코드는 괜찮다고 생각합니다만, 곤란합니다.내부 데이터베이스를 사용하고 있습니다.

패키지...

@Entity

public class Course {
    // here generate constructors and getters/setters
    @Id
    private String id;
    private String Name;
    private String description;

    @ManyToOne
    private Topic topic; //use it to tie this class to the Topic class, to make it easier for the user

    public Topic getTopic() {
        return topic;
    }

    public void setTopic(Topic topic) {
        this.topic = topic;
    }

    public Course() {
    }

    public Course(String id, String name, String description, String topicId) {
        super();
        this.id = id;
        Name = name;
        this.description = description;
        this.topic = new Topic(topicId,"","");
    }

    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getName() {
        return Name;
    }
    public void setName(String name) {
        Name = name;
    }
    public String getDescription() {
        return description;
    }
    public void setDescription(String description) {
        this.description = description;
    }
}

또한 컨트롤러:

@RestController() //makes anything a rest controller, every time you build a class and add this on top of it
public class CourseController {

    @Autowired // it marks the courseService as something that needs dependency inj.
    private CourseService courseService;// To create a service you need a private courseService variable

    //GETALL
    @RequestMapping("/topics/{id}/courses")
    public List<Course> getAllcourses(@PathVariable String id){
        return courseService.getAllCourses(id);  //getAllCourses for the topic ID
    }
    //GET
    @RequestMapping("/topics/{topicId}/courses/{id}") 

    public Course getCourse(@PathVariable String id) {
        return courseService.getCourse(id);
    }

    //POST
    @RequestMapping(method = RequestMethod.POST, value = "/topics/{topicId}/courses")
    public void addCourse(@RequestBody Course course, @PathVariable String topicId) { 
        course.setTopic(new Topic(topicId, "", ""));
        courseService.addCourse(course);
    }

    //PUT
    @RequestMapping(method = RequestMethod.PUT, value = "/topics/{topicId}/courses/{id}")
    public void updateCourse(@RequestBody Course course,  @PathVariable String id,  @PathVariable String topicId) { 
        course.setTopic(new Topic(topicId, "", ""));
        courseService.updateCourse(course);

    }
    //DELETE
    @RequestMapping(method = RequestMethod.DELETE, value = "/topics/{topicId}/courses/{id}")
    public void deletecourse(@PathVariable String id, @PathVariable String topicId) {
        courseService.deleteCourse(id);

    }
}

그리고 마지막으로 서비스 클래스:

package io.msela.springbootstarter.course;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CourseService {

    @Autowired // it injects the courseRepository as it's initialized
    private CourseRepository courseRepository;

    public List<Course> getAllCourses(String topicId){ //getting all is not good!
        List<Course> courses = new ArrayList<>() ;
        courseRepository.findByTopicId(topicId).forEach(courses::add);
        return courses;
    }

    public Course getCourse(String id) {
        return courseRepository.findOne(id);
    }

    public void addCourse(Course course) {
        courseRepository.save(course); //save a course to the database
            }

    public void updateCourse(Course course) {
        courseRepository.save(course);
        //save does both add and update
        }


    public void deleteCourse(String id) {
        courseRepository.delete(id);
    }
}

편집: 여기 pom.xml 파일도 있습니다.

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

<groupId>io.msela</groupId>
<artifactId>course-api-data</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>course-api-data</name>
<description>Course API with Spring Data</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.4.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <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>org.apache.derby</groupId>
        <artifactId>derby</artifactId>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>


</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

편집 2

실제 에러는 다음과 같습니다.

컨텍스트 초기화 중 예외가 발생했습니다. 새로 고침 시도 취소: org.springframework.콩류.Unsupplicated Dependency Exception:이름이 'courseController'인 콩을 만드는 중 오류 발생: 'courseService' 필드에 만족스럽지 않은 종속성이 표현되었습니다. 중첩된 예외는 org.springframework입니다.콩류.Unsupplicated Dependency Exception:이름이 'courseService'인 콩을 만드는 동안 오류가 발생했습니다.courseRepository' 필드를 통해 만족스럽지 못한 종속성을 나타냅니다. 중첩된 예외는 org.springframework입니다.콩류.빈크리에이션예외:이름이 'courseRepository'인 콩을 만드는 동안 오류가 발생했습니다.init 메서드를 호출하지 못했습니다.네스트된 예외는 java.lang입니다.부정 인수예외:메서드 public abstract java.util에 대한 쿼리 메타모델을 만들 수 없습니다.io.msela.springbootstarter.course 목록입니다.CourseRepository.findByName(java.lang).문자열)!

이 오류는 Derby에서만 나타납니다.속성 기본값은 다음과 같이 설정되어 있기 때문입니다.

spring.jpa.hibernate.ddl-auto=create-drop

다음과 같이 설정해야 합니다.

spring.jpa.hibernate.ddl-auto=update

상세한 것에 대하여는, https://github.com/spring-projects/spring-boot/issues/7706 를 참조해 주세요.

스프링 부팅에 대한 다음 속성 추가

**#JPA**
      spring.jpa.generate-ddl=true
      spring.jpa.hibernate.ddl-auto=update
      spring.jpa.database=default
      spring.jpa.show-sql=true
**#DATASOURCE**
     spring.datasource.continue-on-error=false
     spring.datasource.generate-unique-name=false
     spring.datasource.username=app

그래, 나도 그의 비디오를 보면서 같은 문제에 직면했어.

application.properties를 다음과 같이 변경했습니다.

#JPA
  spring.jpa.generate-ddl=true
  spring.jpa.hibernate.ddl-auto=update
  spring.jpa.database=default
  spring.jpa.show-sql=true

감사해요.

테이블 이름과 열 이름을 다음과 같이 정의해야 합니다.

@Table(name="Topic")
public class Topic {
    @Id
    @Column(name="topicId")
    private String id;

언급URL : https://stackoverflow.com/questions/45322941/schema-sa-does-not-exist-and-dropping-table

반응형