简体   繁体   中英

No value specified for parameter - Grails

I'm having an issue when using a find by on a domain class:

The error I'm getting is: ERROR util.JDBCExceptionReporter - No value specified for parameter 2

The domain classes are:

class AppDetail {

String name
String url
Boolean active

static hasMany = [authString:AppIdentifier]


static constraints = {
    name(unique:true,blank:false)
    active(nullable:true)
}

class AppIdentifier {

Date added
String authString

static belongsTo = [authString:AppDetail]

static constraints = {

    added()
    authString(blank:false)

}

The find by is:

def identifier = AppIdentifer.findByAuthString('test')
def appDetails = AppDetail.findByAuthString(identifier) 

Can anyone provide any insight into the meaning of this error?

Thanks in advance!

You have too many fields named "authString". Here's another way to redo the same classes:

class AppDetail {

String name
String url
Boolean active

static hasMany = [identifiers:AppIdentifier]


static constraints = {
    name(unique:true,blank:false)
    active(nullable:true)
}

class AppIdentifier {

Date added
String authString

static belongsTo = [appDetail:AppDetail]

static constraints = {

    added()
    authString(blank:false)

}

def identifier = AppIdentifer.findByAuthString('test')
def appDetails = identifier.appDetail

You defined authString both as String AND AppDetail:

String authString

static belongsTo = [authString:AppDetail]

Either remove String authString or change it to AppDetail authString

BTW From the point of view of GORM the property naming doesn't matter. But if you define a property with String in it's name, but of another class, you gonna get maintenance problems in the future.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM