[hibernate-issues] [Hibernate-JIRA] Created: (ANN-641) @OneToMany disables @OnDelete on @ManyToOne

Christian Bauer (JIRA) noreply at atlassian.com
Wed Jul 25 09:36:52 EDT 2007


@OneToMany disables @OnDelete on @ManyToOne
-------------------------------------------

                 Key: ANN-641
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/ANN-641
             Project: Hibernate Annotations
          Issue Type: Bug
          Components: binder
    Affects Versions: 3.3.0.ga
            Reporter: Christian Bauer


This mapping:

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "PARENT_NODE_ID", nullable = true)
    @org.hibernate.annotations.OnDelete(action = org.hibernate.annotations.OnDeleteAction.CASCADE)
    protected Node parent;

Generates the following correct DDL:

    alter table NODE 
        add index FK24A602FC03E1AA (PARENT_NODE_ID), 
        add constraint FK24A602FC03E1AA 
        foreign key (PARENT_NODE_ID) 
        references NODE (NODE_ID) 
        on delete cascade;

However, if you add a bidirectional collection with @OneToMany:

    @OneToMany(mappedBy = "parent")
    private List<Node> children = new ArrayList<Node>();

the DDL is missing the "on delete cascade" option. Workaround is moving the @OnDelete onto the @OneToMany:

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "PARENT_NODE_ID", nullable = true)
    protected Node parent;

    @OneToMany(mappedBy = "parent")
    @org.hibernate.annotations.OnDelete(action = org.hibernate.annotations.OnDeleteAction.CASCADE)
    private List<Node> children = new ArrayList<Node>();

This is not intuitive, and if the binding can't be changed, needs to be documented.


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list