[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2741) Deleting objects on inverse end of many to many relationship

Eugene Voytitsky (JIRA) noreply at atlassian.com
Wed Jun 11 09:42:33 EDT 2008


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2741?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_30396 ] 

Eugene Voytitsky commented on HHH-2741:
---------------------------------------

I'm facing the same problem.

Emmanuel,
1). what kind of cleaning did you mean?

I've tried 2 kinds of clearing: myMappedByCollection.clear() and myMappedByCollection=null and both do nothing -- I can't delete my entity because of foreign key constraint violated.

2). Regarding "That's why it is mappedBy, it is not managed by the ORM."
This is not actually true -- when I put
    @Cascade({org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
to myMappedByCollection then Hibernate *does* manage myMappedByCollection -- it tries to delete not only many-to-many links but also linked subordinate entities too!

I think that it looks like a bug.
I use Hibernate 3.2.6.ga

> Deleting objects on inverse end of many to many relationship
> ------------------------------------------------------------
>
>                 Key: HHH-2741
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2741
>             Project: Hibernate3
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 3.2.1
>            Reporter: James Roper
>
> I have a Class, Stock, that has a bidirectional many to many indexed relationship with itself.  Here is the mapping:
>     @ManyToMany
>     @JoinTable(name = "input_output_stock", joinColumns = @JoinColumn(name = "id_output_stock"), inverseJoinColumns = @JoinColumn(name = "id_input_stock"))
>     @IndexColumn(name = "ix_input_stock")
>     @ForeignKey(name = "stock_output_fk", inverseName = "stock_input_fk")
>     private List<Stock> inputStock;
>     @ManyToMany(mappedBy = "inputStock")
>     private List<Stock> outputStock;
> When I delete stock objects, Hibernate runs the following queries:
> Hibernate: 
>     delete 
>     from
>         input_output_stock 
>     where
>         id_output_stock=?
> Hibernate: 
>     delete 
>     from
>         stock 
>     where
>         id=?
> This causes problems when deleting objects that are at the inverse end of the relationship.  Shouldn't Hibernate be running another query to delete where id_input_stock=?  As far as I can see in the Hibernate documentation and the EJB3 spec, there is no mention that this is the case.

-- 
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