File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Groovy and the fly likes class inheritance in grails Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Groovy
Bookmark "class inheritance in grails" Watch "class inheritance in grails" New topic
Author

class inheritance in grails

charu shila
Greenhorn

Joined: Nov 24, 2001
Posts: 11
Hi All
I have created my classes like this


class Person{

String email
String password

static constraints={
email(unique:true)

}

}


class JobSeeker extends Person{


}

class Recruiter extends Person{


}


and Bootstrap.groovy is..


class BootStrap {

def init = { servletContext ->


new Jobseeker(email:"aa@bb.com",password:"bbbb").save()
new Recruiter(email:"aa@bb.com",password:"bbbb").save()
}
def destroy = {
}
}



Since emails for Jobseeker and Recruiter are the same, why am I not getting any errors.


Thanks
Joseph Swager
Ranch Hand

Joined: Feb 04, 2010
Posts: 41

Hi Charu,

I'm not an expert in grails, but I think your problem is on the extending
the import will ignore any constraints in the source class (Person) that don't have corresponding properties in the importing classes. I know they are extended from Person, but how are you applying this rule in the extended classes on this constraint.

I had a similar problem and this is the documentation I used to fix it:
http://grails.org/doc/latest/ref/Constraints/Usage.html

Hope That helps or gets you steered toward the correct answer.
Thanks,
Joe Swager


"Your work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work. And the only way to do great work is to love what you do." -- Steve Jobs
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: class inheritance in grails