Search code examples
grailsgrails-ormgrails-domain-class

Gorm mapping for inheritance


I'm facing a issue regarding inheritance in Grails. I have a domain class Person.grooy:

class Person{
    String name
    String contactNumber
    Address address
} 

Now I'm extending Person.groovy for Employee and Customer like:

class Employee extends Person{
    String designation
}
class Customer extends Person{
    String interest
}

Now I want separate table in my database for Employee and Customer having columns of Person i.e name,contactNumber and associate address key. How could I achieve this. I searched every where but there is nothing for this aspect. Is this one approach is not possible in GORM. Please answer. Thanks Guys


Solution

  • Finally I managed to get what I want just by placing a grails.persistence.Entity annotation to my child domain classes. I also make my parent i.e. Person.groovy abstract and place in src/groovy.

    Now I have database hierarchy as I expected but some scaffold issues in controller still persist that will also sorted out with your help.