winna
winna

Reputation: 539

MissingMethodException on domain class save in Grails 1.3.7

I'm having a problem calling the save method on a domain object. The error is:

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)

I'm going through an array of FeedHits, updating a flag, and then calling the save method:

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)
        }
    }
}

I've seen other StackOVerflow users have the same problem, but only during tests. This code is in normal release code.

Any help would be appreciated.

EDIT:

Here is the FeedHit object, slightly edited.

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

Upvotes: 0

Views: 397

Answers (1)

Chris
Chris

Reputation: 8109

You need to annotate GORM functions, if you want to use domain class outside grails. See http://www.rimerosolutions.com/using-gorm-standalone-outside-grails/

I would recommend you to use another way than native threads. Try: Quartz-Plugin

Upvotes: 1

Related Questions