私は基本クラスのPersonクラスとPersonクラスを継承しています。ここではいくつかの短い抜粋は以下のとおりです。これは、ID 1および2、1と従業員に2つのエントリが生成されますJPAの継承:同じIDを挿入する方法
Employee e1 = new Employee(...);
Person p1 = new Person(e1);
Boss b = new Boss(...);
Person p2 = new Person(b);
Employee e2 = new Employee(...);
Person p3 = new Person(e2);
e1.save();
p1.save();
b.save();
p2.save();
e2.save();
p3.save();
:
@Entity
public class Person extends Model{
// ATTRIBUTES
@Id
@Column(columnDefinition = "integer")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@Column(columnDefinition = "varchar(20) not null")
protected String firstName;
@Column(columnDefinition = "varchar(20) not null")
protected String lastName;
@Column(columnDefinition = "varchar(20) not null")
protected String password;
@Column(columnDefinition = "varchar(50) not null")
protected String eMail;
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Boss extends Person {
// ATTRIBUTES
@Column(insertable = false, updatable = false)
private String dtype;
@OneToMany(mappedBy = "boss")
private List<Employee> listEmployee;
@Entity
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class Employee extends Person {
// ATTRIBUTES
@Column(insertable = false, updatable = false)
private String dtype;
@Column(columnDefinition = "Varchar(20)")
private String position;
@ManyToOne
private Boss boss;
は、今私は、従業員、ボスと再び従業員を保存したいですid1とid3を持つPersonのid 1,2,3のエントリのエントリ。 e1はEmployeeではid 1、Personではid 1、Bossではid 1、Personではid 2を持ち、e2はEmployeeでid 2を持ちます。人のid 3。
私のprogrammにグローバルカウンタを使用せずにEmployeeとPersonに同じIDを持つEmployeeを挿入することはできますか?
が
パトリック