使用一个双向关联或两个单向关联有什么区别

时间:2019-07-13 16:08:44

标签: java hibernate jpa

将双向关联实现为两个单向关联会在创建表的DDL代码中有所不同。但是无论如何,我都可以使用书面的Java代码。因此,对象查询,更新和删除(如果有)的区别在哪里

@Entity 
public class Employee {
  @Id
  private int Id;

  @OneToOne
  Address address;
}

@Entity
public class Address {
  @Id
  private int Id;

  @OneToOne(mappedBy="address")
  Employee employee;
}

b)

@Entity 
public class Employee {
  @Id
  private int Id;

  @OneToOne
  Address address;
}

@Entity
public class Address {
  @Id
  private int Id;

  @OneToOne
  Employee employee;
}

0 个答案:

没有答案