org.hibernate.exception.SQLGrammarException при попытке сохранить запись - PullRequest
0 голосов
/ 14 июля 2020

Я новичок в мире JPA и гибернации. У меня есть сущность EMPLOYEE, для которой я пытаюсь сохранить простую пустую запись, но продолжаю получать следующее исключение:

 org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet] with root cause java.sql.SQLSyntaxErrorException: Unknown column 'employee0_.employee_id' in 'field list'

Мой класс сущности выглядит так:

package com.workforcesoftware.groupmanagementservice.data.entities;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;

@Entity
@Table(name = "employee")
public class Employee implements Serializable {
  @Id
  @Column(name = "employeeId")
  private String employeeId;
  @Column(name = "displayEmployeeId")
  private String displayEmployeeId;
  @Column(name = "accountId")
  private String accountId;
  @Column(name = "userId")
  private String userId;
  private String firstName;
  private String lastName;
  private String displayName;
  private String birthDate;
  private String phoneNumber;
  private String originalHireDate;
  private String externalMatchId;

  @OneToMany(mappedBy = "employee")
  private List<EffectiveDatedEmployee> effectiveDatedEmployees;
  @OneToMany(mappedBy = "employee")
  private List<Job> jobs;


  public Employee(){ }

  public Employee(String employeeId, String displayEmployeeId, String accountId, String userId, String firstName,
                  String lastName, String displayName, String birthDate, String phoneNumber, String originalHireDate,
                  String externalMatchId, List<EffectiveDatedEmployee> effectiveDatedEmployees, List<Job> jobs) {
    this.employeeId = employeeId;
    this.displayEmployeeId = displayEmployeeId;
    this.accountId = accountId;
    this.userId = userId;
    this.firstName = firstName;
    this.lastName = lastName;
    this.displayName = displayName;
    this.birthDate = birthDate;
    this.phoneNumber = phoneNumber;
    this.originalHireDate = originalHireDate;
    this.externalMatchId = externalMatchId;
    this.effectiveDatedEmployees = effectiveDatedEmployees;
    this.jobs = jobs;
  }
}

Интерфейс моего репозитория выглядит так:

public interface EmployeeRepository extends JpaRepository<Employee, String> {
}

Наконец, код вызова моего репозитория выглядит так:

    Employee employee = new Employee("1", "", "", "", "", "", "", "", "", "", "", null, null);
    employeeRepository.save(employee);
...