title: Grails delete method
body: <p>The Grails delete method doesn't seem to work.
  I wondered if something was wrong.
  I couldn't solve it myself.
  I would be happy if you could help me.
  I am a Japanese who is not good at English. I'm sorry if I make a mistake in English. X(</p>
  <p>I referred to the tutorial site.
  <a href="https://koji-k.github.io/grails-tutorial/tutorials/todo-application/delete.html" rel="nofollow noreferrer">https://koji-k.github.io/grails-tutorial/tutorials/todo-application/delete.html</a></p>
  <p><strong>Thing you want to do</strong>
  I want to delete the element with the specified id using the delete method.</p>
  <p><strong>Current status</strong>
  Can be saved, but cannot be deleted.</p>
  <p><strong>Development environment</strong>
  MacOS Mojave
  Intellij
  Grails Version: 4.0.1
  JVM Version: 11.0.2</p>
  <p><strong>Domain</strong></p>
  <pre><code>package hoge
  
  class Hoge {
      String name
      String text
      static constraints = {
      }
  }
  </code></pre>
  <p><strong>Controller</strong></p>
  <pre><code>    package hoge
      
      class HogeController {
      
          def index() {
              render(view: '/hoge/index', model: [hoges: Hoge.listOrderById()])
          }
      
          def save() {
              String text = params.text
              String name = params.name
              Hoge newHoge = new Hoge(name: name, text: text)
              // DB save
              if (newHoge.validate()) {
                  newHoge.save()
                  redirect(controller: &quot;hoge&quot;, action: &quot;index&quot;)
              } else {
                  render(view: '/hoge/index', model: [errorHoge: newHoge, hoges: Hoge.listOrderById()])
              }
      
          }
          def delete() {
              Hoge hoge = Hoge.get(params.long(&quot;id&quot;))
              if (hoge) {
                  hoge.delete()
                  flash.message = &quot;deleted&quot;
  
              } else {
                  flash.error = &quot;TodoId:${params.long(&quot;id&quot;)} is not found&quot;
              }
          redirect(controller: &quot;hoge&quot;, action: &quot;index&quot;)
      }
  }
  </code></pre>
  <p><strong>View</strong></p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta charaset=&quot;UTF-8&quot;&gt;
      &lt;title&gt;create page&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;g:if test=&quot;${flash.message}&quot;&gt;
          &lt;div style=&quot;background-color: #269abc&quot;&gt;${flash.message}&lt;/div&gt;
      &lt;/g:if&gt;
      &lt;g:if test=&quot;${flash.error}&quot;&gt;
          &lt;div style=&quot;background-color: #db7093&quot;&gt;${flash.error}&lt;/div&gt;
      &lt;/g:if&gt;
      &lt;g:renderErrors bean=&quot;${errorHoge}&quot; as=&quot;list&quot; field=&quot;hogeName&quot;/&gt;
  
  
      &lt;p&gt;Name and Text&lt;/p&gt;
      &lt;g:form controller=&quot;hoge&quot; action=&quot;save&quot;&gt;
          &lt;g:textField name=&quot;name&quot; placeholder=&quot;name&quot;/&gt;
          &lt;g:textField name=&quot;text&quot; placeholder=&quot;text&quot;/&gt;
          &lt;g:submitButton name=&quot;Add&quot;&gt;Add Todo&lt;/g:submitButton&gt;
      &lt;/g:form&gt;
      &lt;ul&gt;
      &lt;g:each in=&quot;${hoges}&quot; var=&quot;hoge&quot;&gt;
          &lt;li&gt;${hoge.id} ${hoge.name} ${hoge.text}&lt;/li&gt;
          &lt;g:link controller=&quot;hoge&quot; action=&quot;delete&quot; params=&quot;['id':hoge.id]&quot;&gt;
              Delete
          &lt;/g:link&gt;
          &lt;g:link controller=&quot;hoge&quot; action=&quot;update&quot; params=&quot;['id':hoge.id]&quot;&gt;
              kousin
          &lt;/g:link&gt;
      &lt;/g:each&gt;
      &lt;/ul&gt;
  &lt;/body&gt;
  </code></pre>
  <p><strong>build.gradle</strong></p>
  <pre><code>buildscript {
      repositories {
          maven { url &quot;https://repo.grails.org/grails/core&quot; }
      }
      dependencies {
          classpath &quot;org.grails:grails-gradle-plugin:$grailsVersion&quot;
          classpath &quot;org.grails.plugins:hibernate5:7.0.0&quot;
          classpath &quot;gradle.plugin.com.github.erdi.webdriver-binaries:webdriver-binaries-gradle-plugin:2.0&quot;
          classpath &quot;com.bertramlabs.plugins:asset-pipeline-gradle:3.0.10&quot;
      }
  }
  
  version &quot;0.1&quot;
  group &quot;hoge&quot;
  
  apply plugin:&quot;eclipse&quot;
  apply plugin:&quot;idea&quot;
  apply plugin:&quot;war&quot;
  apply plugin:&quot;org.grails.grails-web&quot;
  apply plugin:&quot;com.github.erdi.webdriver-binaries&quot;
  apply plugin:&quot;org.grails.grails-gsp&quot;
  apply plugin:&quot;com.bertramlabs.asset-pipeline&quot;
  
  repositories {
      maven { url &quot;https://repo.grails.org/grails/core&quot; }
  }
  
  configurations {
      developmentOnly
      runtimeClasspath {
          extendsFrom developmentOnly
      }
  }
  
  dependencies {
      developmentOnly(&quot;org.springframework.boot:spring-boot-devtools&quot;)
      compile &quot;org.springframework.boot:spring-boot-starter-logging&quot;
      compile &quot;org.springframework.boot:spring-boot-autoconfigure&quot;
      compile &quot;org.grails:grails-core&quot;
      compile &quot;org.springframework.boot:spring-boot-starter-actuator&quot;
      compile &quot;org.springframework.boot:spring-boot-starter-tomcat&quot;
      compile &quot;org.grails:grails-web-boot&quot;
      compile &quot;org.grails:grails-logging&quot;
      compile &quot;org.grails:grails-plugin-rest&quot;
      compile &quot;org.grails:grails-plugin-databinding&quot;
      compile &quot;org.grails:grails-plugin-i18n&quot;
      compile &quot;org.grails:grails-plugin-services&quot;
      compile &quot;org.grails:grails-plugin-url-mappings&quot;
      compile &quot;org.grails:grails-plugin-interceptors&quot;
      compile &quot;org.grails.plugins:cache&quot;
      compile &quot;org.grails.plugins:async&quot;
      compile &quot;org.grails.plugins:scaffolding&quot;
      compile &quot;org.grails.plugins:events&quot;
      compile &quot;org.grails.plugins:hibernate5&quot;
      compile &quot;org.hibernate:hibernate-core:5.4.0.Final&quot;
      compile &quot;org.grails.plugins:gsp&quot;
      compileOnly &quot;io.micronaut:micronaut-inject-groovy&quot;
      console &quot;org.grails:grails-console&quot;
      profile &quot;org.grails.profiles:web&quot;
      runtime &quot;org.glassfish.web:el-impl:2.1.2-b03&quot;
      runtime &quot;com.h2database:h2&quot;
      runtime &quot;org.apache.tomcat:tomcat-jdbc&quot;
      runtime &quot;javax.xml.bind:jaxb-api:2.3.0&quot;
      runtime &quot;com.bertramlabs.plugins:asset-pipeline-grails:3.0.10&quot;
      testCompile &quot;org.grails:grails-gorm-testing-support&quot;
      testCompile &quot;org.mockito:mockito-core&quot;
      testCompile &quot;org.grails:grails-web-testing-support&quot;
      testCompile &quot;org.grails.plugins:geb&quot;
      testCompile &quot;org.seleniumhq.selenium:selenium-remote-driver:3.14.0&quot;
      testCompile &quot;org.seleniumhq.selenium:selenium-api:3.14.0&quot;
      testCompile &quot;org.seleniumhq.selenium:selenium-support:3.14.0&quot;
      testRuntime &quot;org.seleniumhq.selenium:selenium-chrome-driver:3.14.0&quot;
      testRuntime &quot;org.seleniumhq.selenium:selenium-firefox-driver:3.14.0&quot;
  }
  
  bootRun {
      jvmArgs(
          '-Dspring.output.ansi.enabled=always', 
          '-noverify', 
          '-XX:TieredStopAtLevel=1',
          '-Xmx1024m')
      sourceResources sourceSets.main
      String springProfilesActive = 'spring.profiles.active'
      systemProperty springProfilesActive, System.getProperty(springProfilesActive)
  }
  
  webdriverBinaries {
      chromedriver '2.45.0'
      geckodriver '0.24.0'
  }
  
  tasks.withType(Test) {
      systemProperty &quot;geb.env&quot;, System.getProperty('geb.env')
      systemProperty &quot;geb.build.reportsDir&quot;, reporting.file(&quot;geb/integrationTest&quot;)
      systemProperty &quot;webdriver.chrome.driver&quot;, System.getProperty('webdriver.chrome.driver')
      systemProperty &quot;webdriver.gecko.driver&quot;, System.getProperty('webdriver.gecko.driver')
  }
  
  
  assets {
      minifyJs = true
      minifyCss = true
  }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/TmLHa.png" rel="nofollow noreferrer">It remains even if I try to delete it</a></p>
  <p>In case of todo.delete (flush: true)</p>
  <pre><code>Error 500: Internal Server Error
  URI: /hoge/delete/2
  Class: javax.persistence.TransactionRequiredException
  Message: null
  Caused by: no transaction is in progress
  </code></pre>