1
votes

I am creating a simple web app using groovy-grails and angular JS. I have 4 domain objects (Developer, Tester, Programmer) that all extend Person. In my bootstrap.groovy file, I have created new Developers, Testers, and Programmers, but when I run my app, it doesn't populate the table with whats in the Bootstrap.Groovy file. Whenever I take (extends Person) off of the class header, and add String firstName, then it finds the name of the Developer, Tester and Programmer. I also tried extending an abstract Person class (not a domain object), and that failed as well. See Below:

//domain object
class Person{
     int id;
     String firstName;
     String lastName;
}

//domain object, non working copy
class Developer extends Person{
}

//domain object, working copy
class Developer{
     int id;
     String firstName;
     String lastName;
}

//Boostrap.groovy
new Developer(id: 2, firstName: 'Foo', lastName: 'Ninja');

Thanks, Butler_Alfred

1

1 Answers

1
votes

Try removing the id from your domain classes. Grails adds this field for you implicitly.

Also, when you create a new Developer instance in Bootstrap.groovy, don't pass in your own id. One will be automatically set when the developer instance is persisted.

Developer developer = new Developer(firstName: 'Foo', lastName: 'Ninja')
assert developer.id == null    // id is null before save
developer.save()
assert developer.id != null    // id is assigned after save