diff --git a/CHANGELOG.md b/CHANGELOG.md index a64cabe9..2de4d0fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### 🐛 Fixed + +- Fixes a regression on [OOE-26](https://ortussolutions.atlassian.net/browse/OOE-26) where empty string values are coerced to `NULL` when an ORM type *is* declared. Originally reported against `6.4.0`, resolved in `6.5.0`, then regressed in `6.5.1`. - Resolves [OOE-26](https://ortussolutions.atlassian.net/browse/OOE-26). ### 🔐 Security diff --git a/extension/src/main/java/ortus/extension/orm/HibernateCaster.java b/extension/src/main/java/ortus/extension/orm/HibernateCaster.java index 96e74f00..5ec998ba 100755 --- a/extension/src/main/java/ortus/extension/orm/HibernateCaster.java +++ b/extension/src/main/java/ortus/extension/orm/HibernateCaster.java @@ -501,10 +501,13 @@ public static Object toHibernateValue( Component entity, Property property ) thr String ormType = CommonUtil.toString( meta.get( CommonUtil.ORMTYPE, "" ) ); String fieldType = !ormType.trim().isEmpty() ? ormType : property.getType(); - boolean isStringSafeField = ( fieldType == null || !fieldType.trim().isEmpty() || !CFConstants.STRINGLIKE_FIELDS.contains( fieldType ) ); + boolean isStringSafeField = ( ormType == null || ormType.trim().isEmpty() || CFConstants.STRINGLIKE_FIELDS.contains( ormType ) ); // If the value is an empty string, and the field type is not "string-safe", coerce to a null. if ( value instanceof String && ( ( String ) value ).trim().isEmpty() && !isStringSafeField ) { + logger.atDebug().log( + "toHibernateValue: Coercing {} property to a NULL, since the ORMtype [{}] or fieldType [{}] is not a string-safe field (one of [{}]", + property.getName(), ormType, fieldType, CFConstants.STRINGLIKE_FIELDS ); return null; } diff --git a/tests/models/KitchenSink.cfc b/tests/models/KitchenSink.cfc index 299e4ab4..5fa95833 100644 --- a/tests/models/KitchenSink.cfc +++ b/tests/models/KitchenSink.cfc @@ -85,6 +85,12 @@ component persistent="true" { ormtype="timestamp" default="2023-07-29T04:56"; + property + name ="expireDate" + notnull="false" + ormtype="timestamp" + default=""; + this.name = "KitchenSink"; }