I've got two entities Author and Source in @ManyToMany relation. When I remove record from author table I want to remove also links in author_source table, when I remove record from source table I want to remove links from author_source table. How to achieve this functionality? How should I annotate entities and should I remove links in remove() method of DAO by clearing collections?
I've tried something like this
With this code, whenever I try to remove author, author record is removed and appropriate records from author_source table are also removed. But when I remove source record, links from author_source tables are NOT removed and exception is thrown
org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.example.Source#1]
Thanks for replies.
posted 5 years ago
When I have a many-to-many relationship, I create a class to represent the relationship table.
You can try creating an AuthorSource class and see what happens.