Search code examples
databasegrailsgrails-orm

groovy.lang.MissingMethodException - Save GORM


I'm a new developer for groovy grails and I have a table named user under the database test. I succeed to login to that database by using grails but I couldn't succeed to register the new user. I have used GORM to import into database but there is a strange error and I couldn't find any possible solution to fix this.

ERROR I GET

My domain class

package com.example.ulu

import grails.persistence.Entity;

@Entity
class User {

    String userName
    String password
    String fullName


    static constraints = {

    }
}

Controller

def registeruser = { 

    User a = new User()
    a.fullName("John")
    a.userName("burak")
    a.password("1") 
    a.save()


}

Plug-in's and dependencies

dependencies {

        runtime 'mysql:mysql-connector-java:5.1.29'

        test "org.grails:grails-datastore-test-support:1.0.2-grails-2.4"
        compile "javax.validation:validation-api:1.1.0.Final"
        compile "org.grails:grails-spring:2.4.5"
        compile "org.codehaus.groovy:groovy-all:2.4.5"
        runtime "org.hibernate:hibernate-validator:5.0.3.Final"

    }

    plugins {

        build ":tomcat:8.0.22"


        compile ":scaffolding:2.1.2"
        compile ':cache:1.1.8'
        compile ":asset-pipeline:2.1.5"
        runtime ":resources:1.2.14"


        runtime ":hibernate4:4.3.8.1"
        runtime ":database-migration:1.4.0"
        runtime ":jquery:1.11.1"
    }

Solution

  • a.fullName("John")
    a.userName("burak")
    a.password("1") 
    

    this is all wrong. Groovy uses JavaBean notation, and the property-assignment must look like:

    a.fullName = "John"
    a.userName = "burak"
    a.password ="1"
    

    or

    a.setFullName "John"
    a.setUserName "burak"
    a.setPassword "1"
    

    or

    a[ 'fullName' ] = "John"
    a[ 'userName' ] = "burak"
    a[ 'password' ] ="1"