2

我正在使用@JoinColumn Annotation 来连接两个表,但链接结果为空值。我究竟做错了什么?有没有办法调试链接过程?也许它与sql数据库有关,我的意思是不能进行链接?你可以说我已经尝试了所有关于代码的方法,所以我只是不确定代码是否可能是问题所在。我还使用 Postman 发送 JSON 字符串,也许问题就在那里,但这只是猜测。请帮忙。

@Entity
@Data
public class Operator {


    @Id
    @GeneratedValue
    private int idOperator;

    @Column
    private String login;

    @Column
    private String password;


    @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
    @JoinColumn(name= "id_employee")
    private Employee employee;

@Entity
@Data
public class Employee {

    @Id
    @GeneratedValue
    private int id_employee;

    @Column
    private String firstName;

    @Column
    private String lastName;

    @OneToOne(mappedBy = "employee")
    private Operator operator;
    
}


@RestController
@RequiredArgsConstructor
public class EmployeeController {

    private final EmployeeRepository employeeRepository;


    @PostMapping("/employees")
    public Employee newEmployee(@RequestBody Employee newEmployee) {
        return employeeRepository.save(newEmployee);
    }


@RestController
@RequiredArgsConstructor
public class OperatorController {

    private final OperatorRepositry operatorRepositry;


    @PostMapping("/operators")
    public Operator newOperator(@RequestBody Operator newOperator) {
        return operatorRepositry.save(newOperator);
    }


The debug result: 

    2020-10-12 11:40:19.467 DEBUG 83385 --- [nio-8080-exec-2] org.hibernate.SQL                        : insert into operator (id_employee, login, password, id_operator) values (?, ?, ?, ?)
    2020-10-12 11:40:19.470 TRACE 83385 --- [nio-8080-exec-2] o.h.type.descriptor.sql.BasicBinder      : binding parameter [1] as [INTEGER] - [null]
    2020-10-12 11:40:19.471 TRACE 83385 --- [nio-8080-exec-2] o.h.type.descriptor.sql.BasicBinder      : binding parameter [2] as [VARCHAR] - [dbuser]
    2020-10-12 11:40:19.472 TRACE 83385 --- [nio-8080-exec-2] o.h.type.descriptor.sql.BasicBinder      : binding parameter [3] as [VARCHAR] - [skdbpassword]
    2020-10-12 11:40:19.472 TRACE 83385 --- [nio-8080-exec-2] o.h.type.descriptor.sql.BasicBinder      : binding parameter [4] as [INTEGER] - [7]
    select operator0_.id_operator as id_opera1_1_1_, operator0_.id_employee as id_emplo4_1_1_, operator0_.login as login2_1_1_, operator0_.password as password3_1_1_, employee1_.id_employee as id_emplo1_0_0_, employee1_.first_name as first_na2_0_0_, employee1_.last_name as last_nam3_0_0_ from operator operator0_ left outer join employee employee1_ on operator0_.id_employee=employee1_.id_employee where operator0_.id_operator=?
4

0 回答 0