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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:35:20+00:00 2026-05-13T15:35:20+00:00

I have the following classes: class Catalog { static mapping = { id composite:[‘name’,

  • 0

I have the following classes:


class Catalog {
  static mapping = {
    id composite:['name', 'manufacturer']
    columns {
      name column:'cat_name'
      manufacturer column:'manuf_id'
    }
  }
  String name
  Manufacturer manufacturer
}

class Order {
  static mapping = {
    columns {
      // How to rename foreign keys as cat_name, manuf_id?
    }
  }
  Catalog catalog // creates catalog_name, catalog_manufacturer_name
}

Presently, an Order table is generated with the attributes catalog_name and catalog_manufacturer_name (which reference the composite primary keys of the Catalog table).

I need to rename these generated columns to cat_name and manuf_id in the Order table to work with an existing database. Is this possible, and if so, how?

  • 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-13T15:35:21+00:00Added an answer on May 13, 2026 at 3:35 pm

    It’s not possible using GORM configuration, but you can do it with a custom Configuration class:

    package com.foo.bar;
    
    import java.util.Collection;
    import java.util.Iterator;
    
    import org.codehaus.groovy.grails.orm.hibernate.cfg.DefaultGrailsDomainConfiguration;
    import org.hibernate.MappingException;
    import org.hibernate.mapping.Column;
    import org.hibernate.mapping.PersistentClass;
    import org.hibernate.mapping.RootClass;
    
    public class CompositeAwareHibernateConfiguration extends DefaultGrailsDomainConfiguration {
    
       private static final long serialVersionUID = 1;
    
       private boolean _alreadyProcessed;
    
       @SuppressWarnings("unchecked")
       @Override
       protected void secondPassCompile() throws MappingException {
          super.secondPassCompile();
    
          if (_alreadyProcessed) {
             return;
          }
    
          for (PersistentClass pc : (Collection<PersistentClass>)classes.values()) {
             if (pc instanceof RootClass) {
                RootClass root = (RootClass)pc;
                if ("com.foo.bar.Order".equals(root.getClassName())) {
                   for (Iterator iter = root.getTable().getColumnIterator(); iter.hasNext(); ) {
                      Column column = (Column)iter.next();
                      if ("catalog_name".equals(column.getName())) {
                         column.setName("cat_name");
                      }
                      else if ("catalog_manufacturer_id".equals(column.getName())) {
                         column.setName("manuf_id");
                      }
                   }
                }
             }
          }
    
          _alreadyProcessed = true;
       }
    }
    

    Put the class in src/java and register it in DataSource.groovy:

    dataSource {
       pooled = true
       driverClassName = ...
       username = ...
       password = ...
       configClass = com.foo.bar.CompositeAwareHibernateConfiguration
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 283k
  • Answers 283k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It may be doing what you want it to on… May 13, 2026 at 4:22 pm
  • Editorial Team
    Editorial Team added an answer This seems to fix that problem: [WebInvoke(BodyStyle = WebMessageBodyStyle.Bare, UriTemplate… May 13, 2026 at 4:22 pm
  • Editorial Team
    Editorial Team added an answer The most straightforward solution would be a logic analyzer, especially… May 13, 2026 at 4:22 pm

Related Questions

I am playing with class generation ( one class for a table - inheritance
I encountered a problem when I tried to implement the ServiceKnownType example from MSDN.
I am trying to wrap my head around database normalization. This is my first
i have the following classes: class A { protected: A *inner; public: .... virtual
I have the following classes: public class Person { public String FirstName { set;

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.