tprebs opened a new issue, #16556:
URL: https://github.com/apache/grails-core/issues/16556
### Expected Behavior
The proxy returns the value using the accessor method getIdentifier() and
not getId()
```groovy
class BaseWidget {
String identifier
static constraints = {
identifier nullable: true
}
}
```
### Actual Behaviour
On Grails 8, reading it from an uninitialised Hibernate proxy returns the
entity's primary key instead of the property `identifier`, and because the
generated accessor is declared to return String, the call fails with a class
cast exception because it is returning a Long instead of a String
java.lang.ClassCastException: class java.lang.Long cannot be cast to class
java.lang.String
### Steps To Reproduce
Full recreation here https://github.com/tprebs/grails-proxy-identifier
showing Grails 7 behvaiour vs Grails 8
1. Create a domain class with a string field called identifier
e.g.
``` groovy
@Entity
base class BaseWidget {
String identifier
static constraints = {
identifier nullable: true
}
}
@Entity
class Widget extends BaseWidget {
String name
static constraints = {
name nullable: true
}
}
@Entity
class Holder {
String label
Widget widget
}
```
2. Perform a query which will return an uninitialised proxy e.g. `Holder
holder = Holder.get(holderId)`
3. access the identifier property e.g. holder.widget.identifier
This should return the identifier text but fails with a ClassCastException
### Environment Information
- JDK 21
- Macos
### Example Application
https://github.com/tprebs/grails-proxy-identifier
### Version
8.0.0-RC2
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]