간단한 그루비 \ Grails의 코드 :Grails의 : org.hibernate.TransientObjectException
def start = {
source.save()
def result = getJson(hotelSite, eng + index, [:])
parse(JSONObject.fromObject(result.json.text()))
render "OK"
}
def parse = {JSONObject json ->
def cities = json.get("filter").cities
println cities
def kievHotels = getJson(hotelSite, eng + root + '/searchhotelsbycity', ['city' : 'kiev'])
kievHotels = JSONObject.fromObject(kievHotels.json.text())
println kievHotels
kievHotels.rows.each { ht->
HotelText hotelText = new HotelText(lang : 'en', name : ht.l_name, description : ht.description, address : ht.address)
hotelText.save(/*flush:true*/)
println "hotel text saved"
Hotel hotel = new Hotel(lat : ht.lat, lon : ht.lon, source : source, sourceid : ht.id)
hotel.addToHotelTexts(hotelText)
//hotel.save(/*flush:true*/)
println "hotel saved"
ht.options.each {op->
new HotelFeatures(lang:'en', name : op, source : source, hotel : hotel).save()
}
println "options saved"
ht.photos.each {ph->
new HotelPhotos(hotel : hotel, photourl : ph, type : 'hotel').save()
}
println "photo saved"
hotel.save()
}
println "THE END"
return "THE END"
}
def getJson = {uri, path, query ->
Thread.sleep(10)
return withHttp(uri: uri) {
return get(path : path, query : query) { resp, json ->
return ['response' : resp, 'json' : json ]
}
}
}
모든 완벽해야하지만, Grails는이 ("시작"방법 \ 폐쇄 실행이 끝난 후 프로그램 인쇄 "끝"예외가 발생합니다, "OK"메시지를 렌더링 한 후 발생 예외) :
org.springframework.dao.InvalidDataAccessApiUsageException : - : com.stanfy.sweethome.domains.Hotel을 객체가 저장되지 않은 과도 인스턴스를 참조는 세척하기 전에 transient 인스턴스를 저장 ; 상자의 예외는
org.hibernate.TransientObjectException입니다 : 객체가 저장되지 않은 transient 인스턴스 참조 - 세척하기 전에 transient 인스턴스를 저장합니다 com.stanfy.sweethome.domains.Hotel 을 java.lang.Thread.run에서을 (org.hibernate.TransientObjectException : Thread.java:619)
에 의한 개체가 저장되지 않은 과도 인스턴스를 참조 - 세척하기 전에 transient 인스턴스를 저장합니다 com.stanfy.sweethome.domains.Hotel ... 1 더