I have a Many-To-Many relationship created between Employee-Project in my code, but when I want to use its throws this exception:
com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name 'employee_project'.
I tried, but I did not succeed finding the root cause of this exception. SO, please help me.
Below are the POJOs for Employee and Project and also the code that throws this exception
Employee pojo:
@Entity
@Table(name = "Employee")
public class Employee {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "EMPLOYEE_ID_PK")
private int employeeIdPk;
@ManyToMany(fetch = FetchType.LAZY, cascade = {
CascadeType.PERSIST,
CascadeType.MERGE
},
mappedBy = "workers")
private Collection<Project> projects = new HashSet<Project>(0);
}
Project pojo:
@Entity
@Table(name = "Project")
public class Project {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "PROJECT_ID_PK")
private int projectIdPk;
@ManyToMany(fetch = FetchType.LAZY, cascade = {
CascadeType.PERSIST,
CascadeType.MERGE
})
@JoinTable(name = "EmployeeProject", joinColumns = {
@JoinColumn(name = "PROJECT_ID_PK") },
inverseJoinColumns = { @JoinColumn(name = "EMPLOYEE_ID_PK") })
Collection<Employee> workers = new HashSet<Employee>(0);
}
Problem code:
Project project = projectRepository.findByProjectIdPk(24);
Collection<Employee> employees = project.getWorkers();
I am using Spring Data Jpa and SQL Server. : Here is a picture of my current database