我有两个不同的实体,一个是 MyCustomer,一个是 MySalesman。数据库以某种方式在角色和地址之间切换
MySalesman实体中的部分代码
@Entity
public class MySalesman implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private String salesid;
private String username;
private int password;
private char gender;
private String dob;
private String role;
private String address;
@OneToMany
private ArrayList<MyTransaction> myTransaction = new ArrayList<MyTransaction>();
@OneToMany
private ArrayList<MyCar> myCar = new ArrayList<MyCar>();
@ManyToMany(mappedBy = "mySalesman")
private ArrayList<MyCustomer> myCustomer = new ArrayList<MyCustomer>();
public MySalesman(String username, int password, char gender, String dob, String role, String address) {
this.username = username;
this.password = password;
this.gender = gender;
this.dob = dob;
this.role = role;
this.address = address;
}
MyCustomer实体中的部分代码
@Entity
public class MyCustomer implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private String custid;
private String username;
private int password;
private char gender;
private String dob;
private String role;
private String address;
@OneToMany
private ArrayList<MyTransaction> myTransaction = new ArrayList<MyTransaction>();
@ManyToMany
private ArrayList<MySalesman> mySalesman = new ArrayList<MySalesman>();
public MyCustomer(String username, int password, char gender, String dob, String role, String address) {
this.username = username;
this.password = password;
this.gender = gender;
this.dob = dob;
this.role = role;
this.address = address;
}