How to Save records in Database using Grails Services -


i have domain class called classified. class has relation ship(hasmany) media class:

class classified{ static hasmany = [ adresponses: adresponse,mediafiles:media ]  }  class media{      byte[] mediafile } 

when save classified object classified controller, able save parent child object using below code:

def save(){    def med = new media(mediafile: params.mediafile, contenttype:uploadedfile?.contenttype)    classifiedinstance.addtomediafiles(med)    classifiedinstance.save flush:true } 

below classifiedservice save data.

    @transactional     class classifiedservice {           def addad(classified classifiedinstance)    {      classifiedinstance.save flush:true    }  } 

in above "addad" method passing object of classified instance.

save method of classifiedcontroller:

def save(){    def med = new media(mediafile: params.mediafile,  contenttype:uploadedfile?.contenttype)    classifiedinstance.addtomediafiles(med)    classifiedservice.addad(classifiedinstance) } 

nothing happends when try save. on console dont see error.

please let me know why not able save data.

please make sure following :

  1. you have imported domain class on top of service definition

  2. change save method failon save see more errors

    def med = new media(mediafile: params.mediafile, contenttype:uploadedfile?.contenttype) classifiedinstance.addtomediafiles(med) classifiedinstance.save(flush:true,failonerror:true)

  3. please , times restarting sts , since u not seeing error , clean , make refresh dependency if no error close , reopen.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -