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 8023745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:39:09+00:00 2026-06-04T22:39:09+00:00

I have a Grails Service that is marked as transactional and it does a

  • 0

I have a Grails Service that is marked as transactional and it does a lot of stuff.

I am adding code to this method and not getting results that I expect when I step through it:

  1. I have code that calls .save() that cannot be seen in the MySQL backend until the whole method finishes. This is what I would expect given that the service method is transactional.
  2. I have other code that calls .save() that CAN be seen in MySQL before the service method finishes. I don’t understand this and I don’t understand the disparity between this and 1.
  3. I have yet more code that uses the groovy.sql.Sql to insert into the database. I am guessing this is outside of Grails transaction processing, so the fact that this commits before the method ends makes sense. Can I get Grails to manage this inside of the transaction?

Please disabuse me of any errors in my assumptions. Here is some relevant code:

Main Service Method

public void updateDb(Date date) {
        // Create the results
        if (createResults() > 0) {
            createA()
            createB()
        }
}

createA

A a = new a()
a.user = user
a.week = week
a.save()

createB

userWeek = new UserWeek(user: user)
userWeek.number = 1
userWeek.save(flush: true)

createResults

String insert = "insert into ..."
Sql sql = new Sql(dataSource)
sql.execute(insert)

I added flush:true to make it flush, but I now understand that to just flush hibernate but not actually commit the transaction since it is transactional. What am I doing wrong?

  • 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-06-04T22:39:12+00:00Added an answer on June 4, 2026 at 10:39 pm

    You can get groovy.sql.Sql running in the transaction that your service method is using by using the Sql constructor that takes a connection argument instead:

      Sql sql = new Sql(sessionFactory.currentSession.connection())
    

    This should resolve the problem of data getting committed at different times in the same service method.

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

Sidebar

Related Questions

We are using Grails [Spring+Hibernate] and have one service method with @Transactional(readOnly=true). During development
We have an MTOM-enabled web service that is published with Grails and the Metro
Using Grails and CXF, I have published a small web service that looks like
I am working with grails. I have created a service that will delete the
I'm building out a Grails app and realize that a lot of custom stuff
I'm using Grails 1.3.7. I have some code that uses the built-in base64Encode function
I have a number of Grails Services that are singleton Spring beans, not prototypes.
I have code scattered through a Service in a plugin, using AntBuilder like this:
I have created one service in my grails application. in that service 25 methods
I have a Grails service that is a wrapper around a rather complicated singleton

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.