Schema 'SA' does not exist and discards the table

I use Spring Boot to create courses and a theme database. I'm having problems with a bunch of errors that appeared after I made changes to my courses. I'm not sure what happened. Here are the error messages:

 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   :

The memory: testdb database has not been created; instead, a connection is created to the existing database.

Also, here is my course code, the topic code is fine, I think, but I am having problems with this. I am using an internal database.

package...

@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;
    }
}

Also my controller:

@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);

    }
}

And finally, my class of service:

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 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);
    }
}

EDIT: Here is also the pom.xml file

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>

EDIT 2

The actual error is as follows:

, - : org.springframework.beans.factory.UnsatisfiedDependencyException: bean "courseController": , ""; is org.springframework.beans.factory.UnsatisfiedDependencyException: bean "courseService": ""; org.springframework.beans.factory.BeanCreationException: bean "courseRepository": init ; - java.lang.IllegalArgumentException: Could public abstract java.util.List io.msela.springbootstarter.course.CourseRepository.findByName(java.lang.String)!

+8
3

. , :

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

:

spring.jpa.hibernate.ddl-auto=update

: https://github.com/spring-projects/spring-boot/issues/7706

+20

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

Add the following properties for spring loading

**#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
0
source

Source: https://habr.com/ru/post/1682304/


All Articles