Grails 默认排序为“hasMany”域属性
我正在尝试使用映射语句设置我的 hasMany
属性的默认排序。我正在关注 grails 文档,但它对我不起作用(grails 1.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)
...
您发现我的代码中有任何错误吗?
I'm trying to set default sort of my hasMany
attribute using mapping statement. I'm following the grails doc but it doesn't work for me (grails 1.3.5). My code looks like:
class Note {
Calendar sendDate
static belongsTo = Message
}
class Message {
static hasMany = [notes: Note]
static mapping = {
notes sort:'sendDate desc'
}
}
The error message looks like:
...
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)
...
Do you see any mistakes in my code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有几件事可能有助于解决该问题:
sendDate
属性使用Calendar
吗?大多数时候,人们会使用java.util.Date
。将字段类型更改为Date
是否可以解决问题?我用您的映射运行了一个示例,但出现错误。尝试将您的
Message
静态mapping
闭包更改为:A couple things that may help fix the problem:
Calendar
for thesendDate
property? Most of the time, one would use ajava.util.Date
. Does changing the field type to aDate
fix the issue?I ran an example with your mappings and got an error. Try changing your
Message
staticmapping
closure to this:此页面讲述了有关对象关系映射的所有内容,我我的应用程序也有类似的问题。我这样解决了:
希望
这有帮助!
This page tells all about Object Relational Mapping, I had a similar problem with my app. I solved it like so:
and
Hope this helpes!