rzo1 commented on code in PR #144:
URL: https://github.com/apache/openjpa/pull/144#discussion_r3802486738
##########
openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/EnumValueHandler.java:
##########
@@ -116,8 +219,26 @@ public Object toDataStoreValue(ValueMapping vm, Object
val, JDBCStore store) {
public Object toObjectValue(ValueMapping vm, Object val) {
if (val == null)
return null;
- if (_ordinal)
- return _vals[((Number) val).intValue()];
- return Enum.valueOf(vm.getType(), (String) val);
+ if (_useEnumeratedValue) {
+ initEnumeratedValueField(vm.getType());
+ Enum<?> result = _dbToEnum.get(val);
+ if (result == null && val instanceof Number) {
+ result = _dbToEnum.get(((Number) val).intValue());
+ }
+ if (result == null) {
+ result = _dbToEnum.get(val.toString());
+ }
+ return result;
Review Comment:
> Additionally I wonder why `ENUMERATED_VALUE_CLASS` inited with function
call? `EnumeratedValue.class` looks easier
It would be, but it doesn't compile here: `openjpa-jdbc` has no dependency
on `jakarta.persistence-api`, and it doesn't get one transitively either
(`openjpa-jdbc` → `openjpa-kernel` → `openjpa-lib`, none of them pull it). Only
`openjpa-persistence` declares it. There are currently zero `import
jakarta.persistence.*` statements in `openjpa-jdbc/src/main/java`, and I'd
rather not make this ticket the one that introduces the JPA API as a compile
dependency of the JDBC layer.
Moving the detection up into the persistence module doesn't work either,
because one of the two callers — `MappingDefaultsImpl#getStrategy` — is itself
in `openjpa-jdbc`.
--
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]