Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 629649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:46:10+00:00 2026-05-13T19:46:10+00:00

Simple Groovy\Grails code: def start = { source.save() def result = getJson(hotelSite, eng +

  • 0

Simple Groovy\Grails code:

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 ]

            }
        }
    }

All must be perfect but grails throws exception after the end of “start” method\closure execution(program prints “THE END”, renders “OK” message and then throws exception):

org.springframework.dao.InvalidDataAccessApiUsageException: object references an unsaved transient instance – save the transient instance before flushing: com.stanfy.sweethome.domains.Hotel; nested exception is

org.hibernate.TransientObjectException: object references an unsaved transient instance – save the transient instance before flushing: com.stanfy.sweethome.domains.Hotel
at java.lang.Thread.run(Thread.java:619)

Caused by: org.hibernate.TransientObjectException: object references an unsaved transient instance – save the transient instance before flushing: com.stanfy.sweethome.domains.Hotel
… 1 more

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:46:10+00:00Added an answer on May 13, 2026 at 7:46 pm

    In your collection mapping you have to specify cascade=CascadeType.ALL (I don’t know how exactly it will be in groovy).

    The exception means that you have a collection whose elements are not persisted. Hibernate persists them automatically only if the above option is set.

    P.S. There are hundreds of threads (on SO as well) about this exception, you could’ve searched.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to connect a simple groovy script to the DB. Code: import
I want to write a simple web service in groovy/grails which will retun some
I have a simple groovy script that generates xml def builder = new groovy.xml.StreamingMarkupBuilder()
may be too simple groovy question but....please help i have a list like this:
I am running a simple script in Groovy on an Ubuntu 11.10 machine, which
I have a very simple task I am trying to do in Groovy but
I am trying to create a simple portlet for Liferay 5.2.2 using Grails 1.2.1
I've developed a simple webflow in Grails (mostly to experiment with using webflows- its
I'm new to Grails (but not to Groovy or web development). I'm trying to
I have a Spring/JPA/Groovy/Hibernate stack, (note: not grails ), and I'm finding that I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.