Grails对象不是声明类的实例

时间:2012-12-02 11:57:12

标签: grails groovy gorm

当我执行标准时,我收到以下错误。请帮助。

错误:

2012-12-02 19:50:43,678 [http-8080-2] ERROR property.BasicPropertyAccessor  - IllegalArgumentException in class: indiaweatherstation.WeatherStation, getter method of property: id
2012-12-02 19:50:43,683 [http-8080-2] ERROR errors.GrailsExceptionResolver  - Exception occurred when processing request: [GET] /IndiaWeatherStation/
Stacktrace follows:
    java.lang.IllegalArgumentException: object is not an instance of declaring class
        at grails.orm.HibernateCriteriaBuilder.invokeMethod(HibernateCriteriaBuilder.java:1163)
        at indiaweatherstation.CrawlerController$_closure1_closure3.doCall(CrawlerController.groovy:140)
        at indiaweatherstation.CrawlerController$_closure1.doCall(CrawlerController.groovy:19)
        at indiaweatherstation.CrawlerController$_closure1.doCall(CrawlerController.groovy)
        at java.lang.Thread.run(Thread.java:662)

搜索:

 def awsdata = AWSData.withCriteria {

                        eq("station", station)
                    and {
                    eq("day",dayObject)
                    }
                    }

域:

class AWSData {

    static hasOne =[station:WeatherStation, day:Day, slp:SLP,
        mslp:MSLP, rain:Rainfall, tempreature:Tempreature, 
        point:DewPoint, windSpeed:WindSpeed, 
        windDir:WindDirection, ptend:PTEND, sshm:SSHM]

    int id
    String tmax
    String tmin
    static constraints = {
        station (blank:true, nullable:true)
        day     (blank:true, nullable:true)
        slp     (blank:true, nullable:true)
        mslp    (blank:true, nullable:true)
        rain  (blank:true, nullable:true)
        tempreature (blank:true, nullable:true)
        point (blank:true, nullable:true)
        windSpeed (blank:true, nullable:true)
        windDir (blank:true, nullable:true)
        ptend (blank:true, nullable:true)
        sshm (blank:true, nullable:true)
        tmax (blank:true, nullable:true)
        tmin (blank:true, nullable:true)


    }
}

class WeatherStation {

    static hasOne= [district:District]
    static hasMany = [AWSData:AWSData, ARGData:ARGData,
        HWSRData:HWSRData, radiationData:RadiationData]
    int id
    String name
    String lat
    String lng

    static constraints = {

        AWSData (blank:true, nullable:true)
        ARGData (blank:true, nullable:true)
        HWSRData (blank:true, nullable:true)
       radiationData (blank:true, nullable:true)
    }
}

2 个答案:

答案 0 :(得分:0)

你的eq语句不应该都在and吗?

def awsdata = AWSData.withCriteria {
  and {
    eq( "station", station )
    eq( "day", dayObject )
  }
}

答案 1 :(得分:0)

原因是我期待一个元素所以应该使用

def awsdata = AWSData.createCriteria().get {
                    and {
                        eq( "station", station)
                        eq( "day", dayObject )
                    }
                }