2013-04-05 103 views
0

請考慮下面的代碼,它試圖在事務中創建一個新的SerpKeyword並打印到控制檯以顯示它的位置。Grails事務永遠不會完成

if (!serpKeyword) { 
     println "I DIDN'T FIND THE KEYWORD!" 
     SerpKeyword.withNewTransaction { 
      println "SO NOW I'M BEGINNING A TRANSACTION" 
      serpKeyword = new SerpKeyword(
        keyword: searchKeyword, 
        geoKeyword: geoKeyword, 
        concatenation: concatenation, 
        locale: locale 
      ) 
      println "NOW I'LL SAVE THE KEYWORD" 
      serpKeyword.save(failOnError: true, flush: true) 
      println "AND NOW THE KEYWORD IS SAVED" 
     } 
    } 

控制檯輸出我馬上看到的是:

I DIDN'T FIND THE KEYWORD! 
SO NOW I'M BEGINNING A TRANSACTION 
NOW I'LL SAVE THE KEYWORD 

我從來沒有看到我的輸出的最後一行,表示該記錄從不保存。我已經嘗試過,無論有沒有我通過save的選項。無論如何,它只是掛了一段時間,最終我得到這堆棧跟蹤:

Got error -1 from storage engine. Stacktrace follows: 
java.sql.SQLException: Got error -1 from storage engine 
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055) 
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956) 
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491) 
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423) 
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936) 
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060) 
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542) 
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734) 
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2019) 
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1937) 
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1922) 
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105) 
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105) 
    at com.reachlocal.grails.sales.AdvertiserConnectionService$_findOrCreateSerpKeyword_closure9$$EO2A9QHA.doCall(AdvertiserConnectionService.groovy:624) 
    at org.grails.datastore.gorm.GormStaticApi.withNewTransaction(GormStaticApi.groovy:696) 
    at com.reachlocal.grails.sales.AdvertiserConnectionService$$EO2A9QHA.findOrCreateSerpKeyword(AdvertiserConnectionService.groovy:615) 
    at com.reachlocal.grails.sales.AdvertiserConnectionService$$EO2A9QHA.createSerpEntryForKeyword(AdvertiserConnectionService.groovy:659) 
    at com.reachlocal.grails.sales.AdvertiserConnectionService$$EO2A9QHA.addKeyword(AdvertiserConnectionService.groovy:51) 
    at com.reachlocal.grails.serp.SerpController$_closure9.doCall(SerpController.groovy:77) 
    at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:195) 
    at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63) 
    at org.jasig.cas.client.session.SingleSignOutFilter.doFilter(SingleSignOutFilter.java:65) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) 
    at java.lang.Thread.run(Thread.java:680) 

什麼給?

+0

也許你的表損壞了。你可以直接插入嗎? – 2013-04-05 19:42:32

回答

1

您可能會收到「遇到錯誤-1從存儲引擎」有以下幾個原因:

  1. 你的數據庫是磁盤空間
  2. 你在你的my.cnf文件有innodb_force_recovery開關
  3. 不匹配的MySQL表空間ID。

解決這個問題的最好辦法是採取看看MySQL error log

0

你有ID生成策略設置爲assigned任何其他的東西比在域類serpKeyword一個sequence/auto

如果您也可以在帖子中添加域類,它將對您有所幫助。