2013-08-22 43 views
0

我在調用域對象上的保存方法時遇到問題。錯誤是:MissingMethodException保存在Grails 1.3.7中的域類保存

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數組,更新標誌,然後調用保存方法:

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

這裏是什麼'alertHit',它在哪裏聲明? –

+0

你可以發佈域對象嗎? – marko

+0

你什麼時候調用updateFeedHits方法? – chalimartines

回答

1

如果您想要在grails之外使用域類,則需要註釋GORM函數。見http://www.rimerosolutions.com/using-gorm-standalone-outside-grails/

我會建議你使用另一種方式比原生線程。請嘗試:Quartz-Plugin

+0

Quartz Plugin已經被使用了。我簡化了這個例子。經過進一步檢查,save()函數不在服務中。調試其他人代碼的樂趣,在他們離開之後很久。重構代碼將保存回grails解決了這個問題。 – winna