grails - Gorm cascaded operations -


i'm trying understand gorm's cascaded deletion. default gorm behavior without modifiers. understand if owning instance of domain class owner owns several instances of owned domain class, when owner instance deleted, owned instances deleted well. if owned instances owned simultaneously 2 different owners , 1 owner deleted. owned instances not deleted because still owned other not deleted owner?

edit: tried perform experiment (at least first part of it) did not achieve expected results. being newbie, i'm quite sure i'm doing wrong. don't know what.

class maincontroller {      def index() {         // creating few instances of owned domain class         def owneda = new owned(name: 'owned a')         def ownedb = new owned(name: 'owned b')         def ownedc = new owned(name: 'owned c')          // make these instances belong instance of ownera         // first create instance of ownera         def ownera = new ownera(name: 'owner a')          // give ownership of instances of owned created         ownera.addtoowned(owneda)         ownera.addtoowned(ownedb)         ownera.addtoowned(ownedc)          // save owner instance         ownera.save(flush: true)          // see how many instances of both owners , owned in our db         println "the number of owner in existence are: " + ownera.count()         println "the number of owned in existence are: " + owned.count()          // delete owner instance         ownera.delete(flush: true)          // see how many instances of both owners , owned in our db after deletion         println "after deletion of ownera instance..."         println "the number of owner in existence are: " + ownera.count()         println "the number of owned in existence are: " + owned.count()     } } 

i did put belongsto in owned class , hasmany in owner class.

output:

...........the number of owner in existence are: 0 number of owned in existence are: 0 after deletion of ownera instance... number of owner in existence are: 0 number of owned in existence are: 0 

hibernate not support "on delete set null" cascading. if owned object owned multiple owners, if delete 1 of owner owned object wont deleted.

you "invaliddataaccessapiusageexception: deleted object re-saved cascade" or fk constraint violation exception

see similar question


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -