Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Grails默认排序为;“有很多”;域属性_Grails_Gorm_Grails Domain Class - Fatal编程技术网

Grails默认排序为;“有很多”;域属性

Grails默认排序为;“有很多”;域属性,grails,gorm,grails-domain-class,Grails,Gorm,Grails Domain Class,我试图使用mapping语句设置我的hasMany属性的默认排序。我遵循grails文档,但它对我不起作用(Grails1.3.5)。我的代码如下所示: class Note { Calendar sendDate static belongsTo = Message } class Message { static hasMany = [notes: Note] static mapping = { notes sort:'sendDa

我试图使用mapping语句设置我的
hasMany属性的默认排序。我遵循grails文档,但它对我不起作用(Grails1.3.5)。我的代码如下所示:

class Note {
    Calendar    sendDate
    static belongsTo = Message
}

class Message {
    static  hasMany = [notes: Note]
    static mapping = {
        notes sort:'sendDate desc'
    }
}
...
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'notes0_.sendDate' in 'order clause'
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
        at com.mysql.jdbc.Util.getInstance(Util.java:384)
...
错误消息如下所示:

class Note {
    Calendar    sendDate
    static belongsTo = Message
}

class Message {
    static  hasMany = [notes: Note]
    static mapping = {
        notes sort:'sendDate desc'
    }
}
...
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'notes0_.sendDate' in 'order clause'
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
        at com.mysql.jdbc.Util.getInstance(Util.java:384)
...

您看到我的代码中有错误吗?

以下几点可能有助于解决问题:

  • 您真的需要为
    sendDate
    属性使用
    日历吗?大多数情况下,人们会使用
    java.util.Date
    。将字段类型更改为
    日期
    是否解决了问题
  • 我使用您的映射运行了一个示例,但出现了一个错误。尝试将
    消息
    静态
    映射
    关闭更改为以下内容:

    static mapping = {
        notes sort: 'sendDate', order: 'desc'
    }
    
讲述了所有关于对象关系映射的内容,我的应用程序也有类似的问题。我是这样解决的:

class Note implements Comparable {
  Calendar sendDate
  static belongsTo = Message

  int compareTo(obj) {
    sendDate.compareTo(obj.sendDate)
  }
}


希望这有帮助

导出您的模式并查看@Aaron中存在的表和列的数量-当我使用默认的hsqldb内存数据库尝试此操作时,它只为
日历
字段创建了一列,一切看起来都正常(我原以为它可能创建了两个列来存储,例如时区或其他东西,但似乎不是这样)。不幸的是,这两个列对我都不起作用。但我解决了一个问题,即我从两个方面定义了关系。我刚刚将“Message Message”添加到Note类中,它就起作用了。:-)但无论如何,感谢您的关注!:-)@马特奥-很高兴知道。我建议将你发现的任何问题作为答案发布出来,然后(在几天内)接受它,以便其他人在遇到问题时知道如何解决。