2014-12-20 20 views
0

應用示例:https://github.com/Hi-Fi/writetable-example-with-grails保存失敗,JSON交Grails中

在示例應用中,控制器通過GSP的頁面使用或與CURL張貼形式時很好地工作。命令的捲曲:

curl "http://localhost:8080/junk/team/save" --data "name=team&players"%"5B0"%"5D.firstName=first&players"%"5B0"%"5D.lastName=last&players"%"5B0"%"5D.position=position&create=Create" --compressed. 

的問題是與使用JSON,這產生相同的(根據轉儲())對象相同的請求,但無法保存嵌套值。

在作出下列與SOAPUI(本地主機:8080 /垃圾/ API/REST):POST

{ 
    name: "Team name", 
    players: [ 
     { 
      firstName: "Player first name", 
      lastName: "Player last name", 
      position: "Player position" 
     } 
    ] 
} 

我只是得到錯誤:

| Error 2014-12-20 21:02:47,050 [http-bio-8080-exec-1] ERROR hibernate.AssertionFailure - an  assertion failure occured 
(this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session) 
Message: null id in junk.Player entry (don't flush the Session after an exception occurs) 
Line | Method 
->> 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
| 615 | run  in java.util.concurrent.ThreadPoolExecutor$Worker 
^ 744 | run . . . in java.lang.Thread 

父對象(隊)仍然保存甚至有這個錯誤。隨着Hibernate4整個保存失敗,所以更新到它沒有幫助。解決這一明確「團隊」,每個「播放器」之類

team.players.each {it.team = team} 

連接帶的形式發佈

回答

0

的一種方式,這一步是自動進行的,但由於某種原因不能使用JSON。 Player對象在團隊對象創建的JSON後:

<[email protected] firstName=first lastName=last position=position deleted=false errors=grails.validation.ValidationErrors: 0 errors $changedProperties=null id=null version=null team=null> 

並與表單POST:

<[email protected] firstName=first lastName=last position=position deleted=false errors=grails.validation.ValidationErrors: 0 errors $changedProperties=null id=null version=null team=junk.Team : (unsaved)> 

這可能不是「正確」的解決方案,所以我還是很高興地聽到,如果有更好的解決方案嵌套一對多 - 列表。