apache / apache/grails-core

<RelationName>Id property is not generated for domain class if relation is placed in an abstract class which is the superclass of the domain class

Open
#11,166 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

### Steps to Reproduce

1. Create 2 Domain classes:
`class Foo {
String x
}`
`class Bar {
String y
}`

2. Create an abstract class in src/groovy package
`abstract class Base {
Bar bar
}`
3. Make Foo to extend the Base
`class Foo extends Base {
String x
}`

### Expected Behaviour
Foo should have an artificial "barId" property allowing to get the bar id without loading the bar relation.

### Actual Behaviour
Foo.get(1).barId results to groovy.lang.MissingPropertyException

### Purpose:
I'm doing this to achieve the same effect as JPA @MappedSuperClass annotation provides. I didn't find any other solution to get a parent-child hierarchy for my domain classes for which the tables will be created only for concrete child classes(no need for a table for a parent). Finally I have used the approach described above, but the problem is that I loose the possibility to get the relation Id without loading the relation in case if the relation is declared in the parent class.

I have also posted a [question](https://stackoverflow.com/questions/53480593/org-hibernate-mappingexception-when-using-tableperconcreteclass-inheritance-stra) in stackoverflow.

### Environment Information

- **Operating System**: MAC OS
- **Grails Version:** 3.2.9
- **JDK Version:** 1.8

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with domain classes Foo and Bar, an abstract Base containing the Bar relation, and Foo extending Base; verify that Foo.get(1).barId raises MissingPropertyException. Trace how Grails generates relation ID properties for inherited domain fields, then confirm that the expected barId property is available without loading the relation.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.