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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:14:45+00:00 2026-06-16T00:14:45+00:00

We have a Domain class like so: class Attribute { List attributeParameters = []

  • 0

We have a Domain class like so:

class Attribute {
  List attributeParameters = []
  static hasMany = [attributeParameters: AttributeParameter]
}

AttributeParameter belongs to an Attribute. There are several other relationships defined here and there is an instance where we need to delete several AttributeParameters across many Attributes. So we’re doing this:

def parameters = AttributeParameter.findAllBySomeOtherCriteria(foo)
parameters*.delete()

That works, however, there is a column in attribute_parameter called attribute_parameters_idx that gets out of sequence. This column exists because we’ve defined the collection as a List. And if we were do to attribute.removeFromAttributeParameters(ap), Grails would automatically adjust this column. But since we’re not removing the data that way, they get out of sequence.

When this happens we get null values back when looping over the collection from Attribute. This is not a cache issue or refreshing the parent issue. What happens is when we do:

attribute.attributeParameters.each { }

Something internally is adding additional rows in the iteration based on the _idx values. Since one (or more) of those rows are missing, Grails is adding a null row in the Collection. You can’t see this when debugging, but you can watch it as the iteration occurs.

My question, finally, is:

  • Is there a way to tell Grails to update the _idx values for a specific collection and if not
  • Is there a way to get this _idx column and modify its values manually via Gorm
  • 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-16T00:14:46+00:00Added an answer on June 16, 2026 at 12:14 am

    I think this comes down to how Hibernate handles collections, especially indexed ones like List. Without using addTo and removeFrom Hibernate doesn’t know it needs to update the indexes.

    As a workaround, I can think of something like this:

    Add an afterDelete event on your AttributeParameter class. In it, you’ll want something like:

    def afterDelete() {
        def sql = new Sql(dataSource)
        sql.execute("update attribute_attribute_parameter set attribute_parameter_idx = " +
        "attribute_parameter_idx - 1 where attribute_parameter_idx > " +
        "(select attribute_parameter_idx from attribute_attribute_parameter where " +
        "attribute_parameter_id = $id and attribute_id = $attribute.id) " +
        "and attribute_id = $attribute.id")
    }
    

    PS. Despite it being private, I think you could use getIndexColumnName() to get the index column name dynamically.

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

Sidebar

Related Questions

I have a domain class: class Author { String name static hasMany = [superFantasticAndAwesomeBooks:
I have the following Grails domain objects class ProductType { String name static hasMany
I have domain like this: class Team { hasOne [leader: Person] hasMany [member: Person]
i have a domain class like package trip.side import java.text.SimpleDateFormat class HotelStay { String
In Grails 1.3.7, I have a domain model like this: abstract class A {
I have a class in my domain model root that looks like this: namespace
If I have a Client domain class, and that Client hasMany Courses. How do
interesting problem: I have a Domain Class which looks like class Dummy { String
I have a domain class that looks like this: class Offerbyuser { Number offerPrice
I have a grails domain class that looks like: class Person { String name

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.