I tried replicating the problem and I did not get an InvalidPropertyException
, but the database schema that was generated was missing the 1:m relationship between Dog
and Leg
.
I believe the problem is related to Pet
being an abstract class. If the Dog
class inherits Set legs
from Pet
, then in order to persist the Leg
instances to the database, the underlying Leg
table needs to have a foreign key of pet_id
**. Since Pet
is an abstract
class, a table is not created for it and therefore no id
column. Therefore, no foreign key can be created in the dependent class, Leg
.
Making the Pet
class a concrete class (moving it to grails-app/domain
and removing the abstract
keyword), means that a table with an id
field will be created. And in the Leg
table, a pet_id
column can/will be created that Hibernate will use to persist/retrieve the Set legs
.
** (or an associative entity table, such as pet_legs
, would need to have the foreign key)
Making the Pet
class concrete, however, will cause all the sub-classes of Pet
to be stored into that table, so if you want each sub-class to have its own table, you could add:
static mapping = {
tablePerHierarchy false
}
to the Dog
class, which will create a Pet
, Dog
, etc table in the db.