Often there is something else we should do with our entities before or after these will be mapped. You can do that right in a mapping defining pre and/or postprocessing code as closures. You will not find a better place for such calculations :) There are 6 hooks to be called during mapping: before, beforeAtoB, beforeBtoA, after, afterAtoB and afterBtoA.The closures can access a, b. Hooks before and after can access the direction flag: true is mapping a to b, false is mapping b to a.
mappingFor a: Person, b: Employee beforeAtoB { // before mapping we need to check whether current user has permissions to work with a Person being mapped securityService.checkUserRightsToAccessPerson(a) } beforeBtoA { // before mapping Employee to Person we should notify logService logService.logStartingImport(securityService.currentUser) } afterAtoB { // after successful mapping we should register accessing a Person securityService.registerAccessToPerson(a) } afterBtoA { // after successful mapping we should log importing an Employee logService.logImportingEmployee(b, securityService.currentUser) }
Well, that's all.