Grails 1.3.7中保存的域类上缺少MethodException
在域对象上调用save方法时遇到问题。错误是:Grails 1.3.7中保存的域类上缺少MethodException,grails,Grails,在域对象上调用save方法时遇到问题。错误是: groovy.lang.MissingMethodException: No signature of method: static my.awesome.Class.FeedHit.save() is applicable for argument types: () values: [] Possible solutions: save(), save(java.lang.Boolean), save(java.util.Map), wait(
groovy.lang.MissingMethodException: No signature of method: static my.awesome.Class.FeedHit.save() is applicable for argument types: () values: []
Possible solutions: save(), save(java.lang.Boolean), save(java.util.Map), wait(), any(), wait(long)
我将遍历FeedHits数组,更新一个标志,然后调用save方法:
void updateFeedHits(Set<FeedHit> list, FeedHitStatus status) {
for (FeedHit feedHit: list) {
feedHit.status = status
try {
feedHit.save()
} catch (Exception ex) {
log.info("unknown exception during update FeedHit", ex)
}
}
}
如果要在grails之外使用域类,则需要对GORM函数进行注释。看
我建议您使用本机线程以外的其他方法。试试:什么是
alertHit
,它在哪里声明?你能发布域对象吗?你什么时候调用updateFeedHits方法?@IanRoberts:copy-pasteerror@chalimartines:tomcat启动时创建/启动线程。此线程将唤醒,然后检查URL中的数据。当检测到数据时,FeedHit对象将被创建并与上述代码一起保存。它位于服务类中。石英插件已被使用。我在简化这个例子。经进一步检查,save()函数不在服务中。调试他人代码的乐趣,在他们离开很久之后。重构代码以将保存放回grails解决了这个问题。
class FeedHit {
Feed feed
String title
String body
String url
FeedHitStatus status
String sourceId
String hash
Date publishedDate
Date dateCreated = new Date()
Integer pos = -1
static constraints = {
alert(nullable: true)
title(nullable: true)
body(nullable: true)
url(nullable: true)
status(nullable: true)
sourceId(nullable: true)
hash(nullable: true)
pos(nullable: true)
publishedDate(nullable: true)
dateCreated(nullable: true)
}
static mapping = {
table('alert_hit')
autoTimestamp false
version(false)
alert(column: 'alert_id')
body(sqlType: 'text')
url(sqlType: 'text')
sourceId(column: 'sourceId')
publishedDate(column: 'publishedDate')
dateCreated(column: 'dateCreated')
}
/**
* Generates a hash from title, body and url.
*/
public AlertHit generateHash() {
StringBuffer sb = new StringBuffer();
if (this.title != null) {
sb.append(this.title);
}
if (this.body != null) {
sb.append(this.body);
}
if (this.url != null) {
sb.append(this.url);
}
if (this.publishedDate != null) {
sb.append(this.publishedDate.getTime());
}
if (sb.length() > 0) {
hash = Md5Hash.hash(sb.toString());
}
this
}
@Override
public String toString() {
return "AlertHit{" +
"id=" + id +
", alert=" + alert +
", title='" + title + '\'' +
", body='" + body + '\'' +
", url='" + url + '\'' +
", status=" + status +
", sourceId='" + sourceId + '\'' +
", hash='" + hash + '\'' +
", publishedDate=" + publishedDate +
", dateCreated=" + dateCreated +
", pos=" + pos +
", version=" + version +
'}';
}
}