简体   繁体   中英

Hibernate cascade issue on delete record

I have issue with cascade a one to many relationship. One of my table contains a component, and the component is linked to another table which is my gallery (gallery have many kind of relationship with other tables.). Then the component is used in one of my base class. I used entity developer to generate the code, and it done it with these lines : Baseinfo.hbm.xml

...
<component>
   ...
   <many-to-one name="LocationMap" class="..." cascade="all">
        <column name="ImageId" not-null="true"/>
    </many-to-one>
</component>

....

Since I needed to set it some times to null, I change not-null to "false". Everything worked fine till I come across deleting a record. After setting LocationMap to null, I check database and I saw the image record still exist. After some foruming I did also add "delete-orphan" to cascade options, man: cascade="all,delete-orphan" but it didn't work, I also put application on debug mode, and after performing save code, I tried this on immediate windows: session.Flush(); and that didn't worked to... I don't wanna go through ugly coding, and Remember to delete a record on later code, cause it don't work... , what should I do?!

I don't think all,delete-orphan supported with many-to-one and component . See this question , with a possible work around.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM