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 :
you have imported domain class on top of service definition
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)
please , times restarting sts , since u not seeing error , clean , make refresh dependency if no error close , reopen.
Comments
Post a Comment