0

Please i need a Simple example of a JPA Entity denoting Enterpries with Contacts. Enterprises having many Contacts referenced by rc_No(String); Look At my code, any problem

@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;
}.....

Look at the Contacts Entity also

@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;
.....
Don Roby
  • 40,677
  • 6
  • 91
  • 113
M.Hussaini
  • 135
  • 1
  • 5
  • 15

0 Answers0