apache / apache/grails-core

GORM Data Service for Abstract domain class not being injected into regular Grails service

Open
#14,488 0 comments 1 reaction 0 assignees View on GitHub
relates-to: gorm
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

### Task List

- [x] Steps to reproduce provided
- [x] Stacktrace (if present) provided
- [x] Example that reproduces the problem uploaded to Github
- [x] Full description of the issue provided (see below)

### Steps to Reproduce

1. Generate two separate domain models, both abstract. The intent is that they would be the root of an inheritance hierarchy.
2. For one model generate a regular Grails service.
3. For the other, generate a GORM Data service.
4. Declare the GORM Data service within the regular service
5. Implement a method which uses
6. Attempt to execute said method during runtime

### Expected Behaviour

The GORM Data service is injected on init and executes as expected

### Actual Behaviour

The GORM Data service is null

```
AAbstractServiceSpec.test something
Condition failed with Exception:

aAbstractService.serviceMethod()
| |
null java.lang.NullPointerException: Cannot invoke method serviceMethod() on null object
at com.abstracts.AAbstractServiceSpec.$tt__$spock_feature_0_0(AAbstractServiceSpec.groovy:15)
at groovy.lang.Closure.call(Closure.java:405)
at groovy.lang.Closure.call(Closure.java:421)
at grails.gorm.transactions.GrailsTransactionTemplate$1.doInTransaction(GrailsTransactionTemplate.groovy:68)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140)
at grails.gorm.transactions.GrailsTransactionTemplate.executeAndRollback(GrailsTransactionTemplate.groovy:65)
```

### Environment Information

- **Operating System**: MacOS 10.15.7
- **GORM Version:** 7.0.4 / 7.0.8
- **Grails Version (if using Grails):** 4.0.3 / 4.0.6
- **JDK Version:** 1.8.0_265

### Example Application

I add this to an example I used for a previous bug:
- https://github.com/jamesdh/gorm-data-services-where-bug/commit/b3b83a1acaa41ecec9684275ec4d368ce613261c

Contributor guide

Open the contributing guide

Research direction

Start with the linked example application and the failing AAbstractServiceSpec.groovy stack trace, then reproduce the case using an abstract domain model, regular Grails service, and GORM Data service. Confirm that the declared data service is injected during initialization and that serviceMethod() executes without the null-object failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
backend
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.