Hi,
I have two tables (customers and clients) and for every client there are many customers, my problem is, if i retrieve the customers record, i want to get the client record as well, i want to know how will i do that using many to one annotation or any solution.
this is my customer class
@Entity @Table(name = "customers", catalog = "sample") public class Customers implements java.io.Serializable {
private Integer id; private Integer clientId; private String firstName; private String lastName;
public Customers(Integer id, Integer clientId, String firstName, String lastName) { this.id = id; this.clientId = clientId; this.firstName = firstName; this.lastName = lastName; }
@Id @GeneratedValue(strategy = IDENTITY) @Column(name = "id", unique = true, nullable = false) public Integer getId() { return this.id; }
public void setId(Integer id) { this.id = id; }
@Column(name = "first_name", length = 15) public String getFirstName() { return this.firstName; }
public void setFirstName(String firstName) { this.firstName = firstName; }
@Column(name = "last_name", length = 15) public String getLastName() { return this.lastName; }
public void setLastName(String lastName) { this.lastName = lastName; } //I dont exactly know if this is correct public Clients getClients() { return clients; }
public void setClients(Clients clients) { this.clients = clients; } }
and this is my client class
@Entity @Table(name = "clients", catalog = "lightning_tote_db") public class Clients implements java.io.Serializable { private Integer id; private String name; private String email;
@Id @GeneratedValue(strategy = IDENTITY) @Column(name = "id", unique = true, nullable = false) public Integer getId() { return this.id; }
public void setId(Integer id) { this.id = id; }
@Column(name = "name", length = 25) public String getName() { return this.name; }
public void setName(String name) { this.name = name; }
@Column(name = "email", length = 25) public String getEmail() { return this.email; }
public void setEmail(String email) { this.email = email; }
}
thanks!
|