Announcement Announcement Module
Collapse
No announcement yet.
beforeInsert return false -> object saved Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • beforeInsert return false -> object saved

    Hello,

    In my domain class I've created the beforeInsert method and I'm checking the value of a property there. In some cases I don't want the object to be persisted to the db, so I'm returning false. I've read that this is supposed to work but it doesn't, the object is still being saved...

    This is my method
    Code:
    def beforeInsert = {
    		if (accion=="update")
    		{
    			QuartzJob tareaBorrado = new QuartzJob(idEmpresa:idEmpresa,idSede:idSede,url:url,accion:'delete')
    			tareaBorrado.save()
    			QuartzJob tareaCrawl = new QuartzJob(idEmpresa:idEmpresa,idSede:idSede,url:urlNueva,accion:'crawl')
    			tareaCrawl.save()
    			return false
    		}
    		else if (accion=="schedule")
    		{
    			Calendar calendario = new GregorianCalendar()
    			calendario.set(calendario.get(Calendar.YEAR),calendario.get(Calendar.MONTH),calendario.get(Calendar.DATE),grailsApplication.config.crawler.reindexacion.hora.toInteger(),grailsApplication.config.crawler.reindexacion.minutos.toInteger())
    			fechaSchedule = calendario.getTime()
    			dateCreated = calendario.getTime()
    		}
    		
    	}
    What I want to achieve is to change an insert wich has the property accion="update" to two inserts, one with accion="delete" and another one with accion="crawl". The rows with accion="delete" and accion="crawl" are inserted without problem, but the row with accion="update" is also persisted.
    Any suggestion?
    Thanks
    Last edited by Saioa; Feb 4th, 2011, 06:57 AM.

  • #2
    This isn't supported for beforeInsert, only beforeUpdate. A missing feature I guess. Not sure if there is a suitable workaround - you'd need to look into what support Hibernate has for this kind of thing. Perhaps a custom event listener?

    Comment


    • #3
      Ok, I'll check Hibernate or try to find another workaround.

      Thanks!

      Comment

      Working...
      X