批处理更新返回了意外的行数,应如何映射它以避免此错误

时间:2019-06-12 14:15:07

标签: spring hibernate

我有两个实体,即“系列”和“季节”,我将通过JSP页面添加一个系列,之后我将转到不同的站点,并添加了系列,并为系列提供了标题以将它们连接起来。尝试删除系列时,我也想删除与之相关的季节。如果删除季节,则应保留序列,但删除季节时,父(序列)的季节也应删除。我试图这样做,但是我遇到了异常。

@Entity
@Table(name = "series")
public class Series {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @Column(name = "title")
    private String title;
    @Column(name = "description")
    private String description;
    @Column(name = "country")
    private String country;
    @Column(name = "director")
    private String director;
    @Column(name = "release_date")
    @Temporal(TemporalType.DATE)
    private Date release_date;
    @OneToMany(mappedBy = "series")
    private List<Season> seasons;
@Entity
@Table(name = "season")
public class Season {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @Column(name = "name")
    private String name;
    @Column(name = "episodes_no")
    private Integer episodesNo;
    @Column(name = "release_date")
    @Temporal(TemporalType.DATE)
    private Date release_date;
    @OneToMany(mappedBy = "season", cascade = {CascadeType.PERSIST, CascadeType.REFRESH})
    @EqualsAndHashCode.Exclude
    private List<Episode> episodes;
    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "series_id")
    private Series series;

我还没有进入休眠状态,刚刚开始学习它,请您给我一些建议,我做错了什么?我想得到上面的结果,当通过JSP删除系列时,我当然有一个采用requestparams的控制器,它将正确删除它,但是异常在数据库中。我认为我搞砸了那些映射。

0 个答案:

没有答案