使用SQL播种数据库不会显示我的employee_project数据库

问题描述

我正在创建一个项目管理应用程序,并且可以在h2-console中查看我的employee_database,project_database,但不能查看employee_project数据库。我正在使用data.sql文件,由于某种原因,在MysqL工作台中列出project_database行的sql文件在它旁边有一个红色x,但是当我在eclipse中打开它时,没有红色x。我很确定这就是为什么它没有出现在h2-console中的原因,但是经过大量在线研究之后,我找不到解决方案。我仍在尝试解决问题,但是如果有一种简单的方法可以解决此问题,而我却完全忽略了该问题,请告诉我。我已附上我的代码的屏幕截图。感谢您的时间和精力。

This is how the data looks like with the red x in MySQL Workbench.

This is the same data file in the eclipse SQL editor tool.

这是我的employee.java文件,project.java和我的主ProjectManagementApplication.java文件

package com.jrp.pma.entities;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;

@Entity
public class Employee {
    
    
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private long employeeId;
    
    private String firstName;
    private String lastName;
    private String email;
    
    
    @ManyToMany(cascade = {CascadeType.DETACH,CascadeType.MERGE,CascadeType.REFRESH,CascadeType.PERSIST},fetch = FetchType.LAZY)
    @JoinTable(name="project_employee",joinColumns=@JoinColumn(name="employee_id"),inverseJoinColumns = @JoinColumn(name="project_id"))
    
    private List<Project> projects;
    
    public Employee() {
        
    }
    
    
    public Employee(String firstName,String lastName,String email) {
        super();
        this.firstName = firstName;
        this.lastName = lastName;
        this.email = email;
    }
    
    public long getEmployeeId() {
        return employeeId;
    }
    public List<Project> getProjects() {
        return projects;
    }


    public void setProjects(List<Project> projects) {
        this.projects = projects;
    }


    public void setEmployeeId(long employeeId) {
        this.employeeId = employeeId;
    }
    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }   
}

这是我的project.java文件

package com.jrp.pma.entities;

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

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;

@Entity
public class Project {
     
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private long projectId;
    private String name;
    private String stage;//NOT STARTED,IN PROGRESS,COMPLETED
    private String description;
    
    @ManyToMany(cascade = {CascadeType.DETACH,joinColumns=@JoinColumn(name="project_id"),inverseJoinColumns = @JoinColumn(name="employee_id"))
    
    private List<Employee> employees;
    
    public Project() {
        
    }
    
    public List<Employee> getEmployees() {
        return employees;
    }
    
    public void setEmployees(List<Employee> employees) {
        this.employees = employees;
    }
    
    public Project(String name,String stage,String description) {
        super();
        this.name = name;
        this.stage = stage;
        this.description = description;
    }


    public long getProjectId() {
        return projectId;
    }
    public void setProjectId(long projectId) {
        this.projectId = projectId;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getStage() {
        return stage;
    }
    public void setStage(String stage) {
        this.stage = stage;
    }
    public String getDescription() {
        return description;
    }
    public void setDescription(String description) {
        this.description = description;
    } 
    
    //convenience method
    public void addEmployee(Employee emp) {
        if(employees == null) {
            employees = new ArrayList<>();
        }
        employees.add(emp);
    }   
}

这是主要的ProjectManagementApplicationFile.java

package com.jrp.pma;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.jrp.pma.dao.EmployeeRepository;
import com.jrp.pma.dao.ProjectRepository;

@SpringBootApplication
public class ProjectManagementApplication {
    
    @Autowired
    EmployeeRepository empRepo;
    
    @Autowired
    ProjectRepository projRepo;

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

最后,这是我的h2-console的屏幕快照,该屏幕快照未显示project_employee数据库。再次感谢您的时间和精力!

employee database as it shows up in the h2-console

project database as it shows up in the h2-console

employee_project database does not show up in the h2-console

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)