apache / apache/grails-core

Grails domain class properties - Grails 3.2 and 3.3 behave differently

Open
#14,568 5 comments 0 reactions 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

Given the following domain classes
```
class A {
String a
int b
boolean c
Set fs
Set efs

static embedded = [ 'efs' ]
}
```
```
class X {
String x
String y
A z
Set fs
Set efs

static embedded = [ 'efs' ]

static mapping = {
id name: 'x', generator: 'assigned'
version false
}
}
```
```
class F {
String f
}
```

In Grails 3.2, to get the list of all domain class' properties:
```
println new DefaultGrailsDomainClass(A.class).persistentProperties.collect { it.name }
> [a, b, c, efs, fs]
println new DefaultGrailsDomainClass(X.class).persistentProperties.collect { it.name }
> [efs, fs, x, y, z]
```

In Grails 3.3, with `GrailsDomainClass` being deprecated and replaced by `PersistentEntity`:
```
println Holders.grailsApplication.mappingContext.getPersistentEntity(A.class.name)?.persistentPropertyNames
> [c, efs, a, b, version]
println Holders.grailsApplication.mappingContext.getPersistentEntity(X.class.name)?.persistentPropertyNames
> [efs, z, version, y]
```

Differences in Grails 3.3:
- `x` property, mapped as id, is not listed
- `fs` property, referencing another domain class, is not listed (while `efs`, declared as embedded, is included as expected)
- `version` property showing up even with disabled versioning for `X` domain class

### Example application

https://github.com/ilPittiz/persistentProperties

Run the application and access http://localhost:8080 (Grails 3.3.5 is predefined).
By editing `gradle.properties` and `MainController.groovy` you can switch between Grails 3.3 and 3.2, and vice-versa.

### Environment Information

- **GORM Version:** 6.1.8
- **Grails Version:** 3.3.5
- **JDK Version:** 1.8.0_171

Contributor guide

Open the contributing guide

Research direction

Run the linked example application, then use gradle.properties and MainController.groovy to compare Grails 3.3.5 with Grails 3.2. Inspect the mappingContext PersistentEntity results for A and X against the older DefaultGrailsDomainClass output. Done means the persistent property names consistently include the mapped id and referenced properties while respecting the disabled version field.

Written by the indexing model from the issue text.

Assessment

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