Hibernate Master Details关系表删除错误

时间:2015-06-01 08:47:40

标签: java mysql spring hibernate

My Spring Hibernate项目有2个表ListNote& ListNoteDetails。 下面给出了映射。数据插入和从表中获取工作正常。  但是当我执行删除主数据时,它会抛出异常。

    @Entity
    @Table(name = "LIST_NOTE")
    public class ListNote implements Serializable {

        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        @Column(name = "ID", nullable = false, length = 11)
        private long id;
        @Column(name = "TITLE", nullable = false)
        private String title;
        @ManyToOne
        @JoinColumn(name = "FOLDER_ID")
        private Folder folder;
        @Column(name = "CREATED_DATE", nullable = false)
        private Date createdDate;

        @OneToMany(fetch = FetchType.EAGER, orphanRemoval = true, cascade =     CascadeType.ALL)
        @Fetch(value = FetchMode.SUBSELECT)
        @JoinColumn(name = "LIST_NOTE_ID")
        private List<ListNoteDetails>details=new ArrayList<ListNoteDetails>();
//getters  & setters.

    }



@Entity
@Table(name = "LIST_NOTE_DETAILS")
public class ListNoteDetails implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "ID", nullable = false, length = 11)
    private long id;
    @Column(name = "POINT", nullable = false)
    private String point;
    @ManyToOne
    @JoinColumn(name = "LIST_NOTE_ID")
    private ListNote listNote;
//getters and setters
}

使用主键i删除ListNote主数据时出现以下错误。

14:10:15,651 WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (http--0.0
.0.0-8080-1) SQL Error: 1048, SQLState: 23000
14:10:15,655 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (http--0.0
.0.0-8080-1) Column 'list_note_id' cannot be null
14:10:15,655 INFO  [org.hibernate.engine.jdbc.internal.LogicalConnectionImpl] (h
ttp--0.0.0.0-8080-1) HHH000106: Forcing container resource cleanup on transactio
n completion
14:10:15,659 INFO  [org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl]
(http--0.0.0.0-8080-1) HHH000010: On release of batch it still contained JDBC st
atements
14:10:15,659 INFO  [stdout] (http--0.0.0.0-8080-1) Column 'list_note_id' cannot
be null; SQL [n/a]; constraint [null]; nested exception is org.hibernate.excepti
on.ConstraintViolationException: Column 'list_note_id' cannot be null

0 个答案:

没有答案