小编Ksh*_*tij的帖子

将实体从多方持久化到一侧时事务会回滚

我在数据库中有这个关联 - 表结构在数据库中看起来像这样 -

我希望数据像这样保存在表中 - 表中的记录

相应的 JPA 实体已按此方式建模(为简单起见,省略了 getter/setter)-

学生实体 -

@Entity 
@Table(name = "student")
public class Student {
    @Id
    @SequenceGenerator(name = "student_pk_generator", sequenceName = 
                              "student_pk_sequence", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = 
                               "student_pk_generator")
    @Column(name = "student_id", nullable = false)
    private Long studentId;

    @Column(name = "name", nullable = false)
    private String studentName;

    @OneToMany(mappedBy = "student", cascade = CascadeType.ALL)
    private Set<StudentSubscription> studentSubscription;
}
Run Code Online (Sandbox Code Playgroud)

STUDENT_SUBSCRIPTION 实体 -

@Entity
@Table(name = "student_subscription")
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class StudentSubscription {
    @Id
    private Long …
Run Code Online (Sandbox Code Playgroud)

jpa spring-data spring-data-jpa spring-boot

1
推荐指数
1
解决办法
911
查看次数

标签 统计

jpa ×1

spring-boot ×1

spring-data ×1

spring-data-jpa ×1