0

请我需要一个 JPA 实体的简单示例,表示带有联系人的企业。rc_No(String) 引用了很多联系人的企业;看我的代码,有什么问题

@Entity
public class Enterprises implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private String rcNo;

@OneToMany(mappedBy = "enterprises", cascade=CascadeType.PERSIST, fetch=FetchType.EAGER)
private List<Contacts> contacts;

public void addContact(Contacts contact) {
    contacts.add(contact);
}

public String getRcNo() {
    return rcNo;
}

public void setRcNo(String rcNo) {
    this.rcNo = rcNo;
}

public String getAddress() {
    return address;
}

public void setAddress(String address) {
    this.address = address;
}.....

还要查看联系人实体

@Entity
public class Contacts implements Serializable {
@ManyToOne
@JoinColumn(name="rcNo")
private Enterprises enterprises;

public Enterprises getEnterprises() {
    return enterprises;
}

public void setEnterprises(Enterprises enterprises) {
    this.enterprises = enterprises;
}

private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String fullName;
private String designation;
private String telephoneNo;
private String emailAddress;
.....
4

0 回答 0