1

Im experiencing a weird behavior using tablePerSubclass inheritance option in GORM (grails 2.4.3)

Having one superclass domain Item

class Item {

    static mapping = {
        tablePerHierarchy false
    }
}

and a subclass, let's say Book

class Book extends Item {
    String      name           
    String      description   
}

I get two tables in MySQL: Item and Book, when i save Book items i can see entries in Item table. Then i delete elements in Books table but Item table still has the reference!!

How is this possible?

Rafael
  • 2,521
  • 2
  • 33
  • 59
  • Ive read http://stackoverflow.com/questions/16686322/how-to-ensure-data-integrity-when-using-table-per-subclass that looks promising but i have same problem with actual 2.4.3 version after the release in which it should be corrected – Rafael Nov 14 '14 at 13:18
  • Do you need to specify cascade? `child cascade: 'all-delete-orphan'` – TJ- Nov 14 '14 at 13:19
  • I expect a FK creation to enforce referential integrity as described https://jira.grails.org/browse/GRAILS-7729 it states that the issue has been closed in 2.3.8 but using 2.4.3 im having same problem. Now, maybe i am missing some configuration option or something ... i don't know – Rafael Nov 14 '14 at 13:25

1 Answers1

0

In this environment when a record is deleted in the child table grails tries to delete the entry in the parent table. However this seems to be done in a different transaction so if this second delete fails then grails is unable to recover to a coherent state.

Rafael
  • 2,521
  • 2
  • 33
  • 59
  • This is not true. You are able to rollback the entire operation using the usual @Transactional annotation. – Rafael Dec 23 '14 at 11:49