1
votes

I have the following problem. I got a database schema generated by JPA/Hibernate in Java. I have one table for an inheritance hierarchy. For this to work Hibernate uses a DTYPE column to distinguish between the concrete implementations of the classes in my hierarchy.

I now need to load that same hierarchy to GRAILS domain objects. However GRAILS uses a column with the name 'class' to save the names of the concrete implementation and I was not able to find any way to change this mapping. So my question is: is there a way to map GRAILS' 'class' column to Hibernate's DTYPE column?

2
What specifically about the mapping are you trying to change? The column name, the datatype, etc??James Kleeh
I think I need to change the column name as well as the value each class is mapped to. But I think the answers below provide help in doing that.ali

2 Answers

3
votes

You can customise the name used for the discriminator column in the base class mapping closure.

class TopOfTheHierarchy {static mapping = {
    discriminator column: "DTYPE"
  }
}

To use something other than the class name as the discriminator value you use a similar mapping entry for each subclass

class ChildClass {static mapping = {
    discriminator "child"
  }
}
0
votes

If you already have a DB schema you can try using Grails Database Reverse Engineering Plugin to generate your Grails domain class from your schema.