JPA插入操作无法正常工作

时间:2018-05-21 09:56:20

标签: oracle jpa insert entity jpa-2.1

需要执行插入操作

 using (var scope = app.ApplicationServices.GetService<IServiceScopeFactory>().CreateScope())
    {
        scope.ServiceProvider.GetRequiredService<ApplicationDbContext>().Database.Migrate();
    }

当我坚持学生详细信息时,地址相关信息未正确插入。当我检查对成员,学生和地址表后触发的插入查询。但是,在插入查询到地址表中,member_id值将变为null。因此,仅填充地址表。

实体结构如下所示

Member {
  member_id // have one to one relation with student_id and teacher_id ( sharing primary key)
  lastupdateddate
  latupdatedby
}

Student {
  student_id // have one to one relation with member_id
  student name
  lastupdateddate
  latupdatedby
}

Teacher {
  teacher_id // have one to one relation ship with member_id
  teacher name
  lastupdateddate
  latupdatedby
}

Address {
  address id
  member_id // have one to one relationship with member_id class
  lastupdateddate
  latupdatedby
}

如下所述提到映射。尝试了各种可用的选项。

在成员实体类中:

public abstract class Member implements Serializable {
}
public class Student extends Member implements Serializable {
}
public class Teacher extends Member implements Serializable {
}
public class Address implements Serializable {
}

在地址实体类中:

@OneToOne(mappedBy="member", cascade=CascadeType.ALL)
private Address address;

我是否在实体级别中遗漏了任何内容,或者这样做是否正确? 该实体使用JpaRepository的saveAndFlush操作进行保存。

0 个答案:

没有答案