2

I have a Foo domain class with an embedded Bar field:

class Foo {
  Bar bar

  static embedded=['bar']
}

class Bar {
  String ham
}

Which gives me a foo table with a bar_ham column.

The problem is that my Foo.bar and Bar.ham have much longer names in reality, so the column ends up having more than 30 characters in length, which Oracle doesn't like.

So how can I customize the name of the embedded column?

I've tried something like the following, but it didn't work:

class Foo {
  Bar bar

  static embedded=['bar']

  static mapping={
    bar column:'b'
  }
}

2 Answers 2

1

Specify the customized column name on the Bar class, like so:

class Foo {
  Bar bar

  static embedded=['bar']

}


class Bar {
    String bazIsReallyLong

    static mapping = {
        bazIsReallyLong column:'baz'
    }
}

Tested on Grails 2.0, this created a Foo table with column names ID, VERSION, and BAZ.

This will affect all tables containing Baz, however.


Updates based on comment

Another options is to change the name of the mapped class to something shorter, like this:

class Foo {
  Bar b

  static embedded=['b']

}


class Bar {
    String bazIsReallyLong
}

This creates the column B_BAZ_IS_REALLY_LONG, which at least helps.

I don't see any options for explicitly renaming embedded columns otherwise.

Sign up to request clarification or add additional context in comments.

3 Comments

Yes, I know this but I only want to customize the column name for the embedding domain class. Plus, what happens if the embedded class is embedded twice?
Well, I think you are SOL. The only solution I can come up with is to map bar to a shorter name on Foo. See updates above.
Also, I agree about the issue with embedding the column twice. I would consider that a bug - the column really should map to table_customname.
0

Please have a look @

@AttributeOverride

section 2.2.2.4.

1 Comment

I just tried but I'm using GORM, not JPA annotations so I suspected it wouldn't work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.