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

  • Home
  • SEARCH
  • 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 8931891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:12:51+00:00 2026-06-15T09:12:51+00:00

On a Grails 2.1.0 I am trying to dynamically updating a field on a

  • 0

On a Grails 2.1.0 I am trying to dynamically updating a field on a domain class. The object gets binded and it looks fine, until the save method is called, which throws the following exception:

java.lang.IllegalStateException: Cannot make an immutable entity modifiable.

    try {
        def bindParams = [:]
        bindParams."$paramsFieldName" = "$paramsValue"
        def domainClass = grailsApplication.domainClasses.find { it.clazz.simpleName == paramsDomain }.clazz
        def objectInstance = domainClass.findById(paramsId)
        objectInstance."$paramsFieldName" = "$paramsValue"
        bindData(objectInstance, bindParams)
        objectInstance.save(flush:true ,failOnError:false)
        return objectInstance
    }
    catch (Exception ex) {
        log.error ex
        return null
    }

I tried to bind the field using direct assigment and worked well.

objectInstance."$paramsFieldName" = convertToType( fieldType.name,paramsValue)

but then I need to handle the type conversion for each case (I assume). What I need is the BindDynamicMethod handles the binding for me. What happens to the object when binding it using the BindDynamicMethod that makes is immutable?. Or what am I doing wrong that is causing it?

=========================================================

PARTIALLY SOLVED

It turned out that this was happening on some of the domains, but some that were using cache on their mapping was throwing this exception.

class UploadSettings {
    String profile = "default"
    String displayName
    String name 
    String value 
    String defaultValue 

    static mapping = {
        //cache usage:'read-only'

    }
}

So I guess now my question is if a domain is using cache , why cant we update its value? Or how can we do that? Is there a way to capture if the domain is immutable?

Thanks

  • 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-15T09:12:52+00:00Added an answer on June 15, 2026 at 9:12 am

    Yes by setting it to read-only you are making the object immutable as the error says, IMHO this is misleading as we are in the context of caching but there is some rationale behind this.

    If you need caching at the domain level then setting it to read-write should do the trick

    See cache usages

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

Sidebar

Related Questions

I've created domain class: grails create-domain-class Trip At now I'm trying: grails generate-all Trip
I am trying to inject 'GraauditService' into grails 'User' domain class. I am using
I'm trying to dynamically create domain objects in Grails and encountered the problem that
I'm trying to create a basic grails domain object and for one of the
i'm trying to learn Grails console and had a problem. It looks like this:
The Grails code below throws the following exception when trying to .save() the Foo
I'm new to grails and trying to write unit tests for Service class has
In grails I am trying to get every instance of a domain called Child
Hi I am trying to make a dynamically created drop down list in grails
I'm using Grails 1.2.1. I have this method in my controller … class SocialMediaCacheProxyController

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.