I am new to hibernate and jpa, I have to create 3 classes User, Client and Attribute that will be mapped to tables, the classes have the following properties:
I do not have many problems creating the user and client classes, but when creating the Attribute class, I find myself somewhat confused, I do not know if I create 2 Attribute classes separated one for the user and another for the client or client. only 1.
For now what I have done is this:
Class User:
public class User {
private String userID;
private String name;
private String surname;
private String password;
private Set<Client> clients = new HashSet();
private Set<UserAttribute> attributes = new HashSet();
public User() {
}
/* getters and setters*/
}
Class Client:
public class Client {
private String clientID;
private String clientName;
private User user;
private Set<ClientAttribute> attributes = new HashSet();
public Client() {
}
/* getters and setters*/
}
Class UserAttribute:
public class UserAttribute {
private String id;
private String name;
private String value;
private User user; // the owner of this attribute
public UserAttribute() {
// TODO Auto-generated constructor stub
}
/* getters and setters*/
}
Class ClientAttribute:
public class ClientAttribute {
private String id;
private String name;
private String value;
private Client client; // the owner of this attribute
public ClientAttribute() {
// TODO Auto-generated constructor stub
}
/* getters and setters */
}
Is the way I write the classes okay? Should I use 2 classes or only 1 for Attribute?