0

我在域对象上调用 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(), 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)
        }
    }
}

我见过其他 StackOVerflow 用户也有同样的问题,但只是在测试期间。此代码为正常发布代码。

任何帮助,将不胜感激。

编辑:

这是 FeedHit 对象,稍作编辑。

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 +
            '}';
    }
}
4

1 回答 1

1

如果要在 grails 之外使用域类,则需要注释 GORM 函数。请参阅http://www.rimerosolutions.com/using-gorm-standalone-outside-grails/

我建议您使用本机线程以外的另一种方式。尝试:石英插件

于 2013-08-27T11:50:59.947 回答