tags:

views:

39

answers:

1

I have two entities: A and B. From the A's side relationship is many to one where many A refer to one B and from the B's side this is one to many, where one B could have many A. Both mappings have cascade ="all".

If I try to delete A, since cascade is enabled on many to one, hibernate will try to delete B, but since one to many on B has also cascade enabled it will go back to A and so forth.. My question is: will it end up in infinite loop or hibernate has a way of detecting those situations and terminating execution?

A: 
            <class   
               name="A" 
               table="tableA"
               <many-to-one name="b" column="B_ID" class="B" cascade="all"/>
             </class>


             <class 
                name="B"
                table ="tableB"
                <set name="someList">
                     <key column="B_ID"/>
                     <one-to-many class="A" cascade ="all"/>
                  </set>
              </class>

I realise that this mapping is incorrect, since you should not have cascade in both directions. But my question is will this incorrect mapping actually cause an infinite looping? Or hibernate is able to detect it?

Renee