jamesfredley commented on code in PR #15731:
URL: https://github.com/apache/grails-core/pull/15731#discussion_r3398876254


##########
grails-data-hibernate7/core/src/main/groovy/org/grails/orm/hibernate/HibernateGormStaticApi.groovy:
##########
@@ -353,22 +354,42 @@ class HibernateGormStaticApi<D> extends GormStaticApi<D> {
         if (!queryMap) return null
         Map coercedMap = queryMap.collectEntries { k, v -> [k.toString(), v] }
         String hql = buildWhereHql(coercedMap)
-        doSingleInternal(hql, coercedMap, [], args, false)
+        doSingleInternal(hql, buildWhereParams(coercedMap), [], 
buildFindWhereArgs(args), false)
     }
 
     @Override
     List<D> findAllWhere(Map queryMap, Map args) {
         if (!queryMap) return null
         Map coercedMap = queryMap.collectEntries { k, v -> [k.toString(), v] }
         String hql = buildWhereHql(coercedMap)
-        doListInternal(hql, coercedMap, [], args, false)
+        doListInternal(hql, buildWhereParams(coercedMap), [], args, false)
     }
 
     private String buildWhereHql(Map queryMap) {
-        String whereClause = queryMap.keySet().collect { Object key -> "$key = 
:$key" }.join(' and ')
+        String whereClause = queryMap.collect { Object key, Object value ->
+            String propertyName = validateWherePropertyName(key.toString())
+            value == null ? "$propertyName is null" : "$propertyName = 
:$propertyName"
+        }.join(' and ')
         return "from ${persistentEntity.name} where $whereClause"
     }
 
+    private String validateWherePropertyName(String propertyName) {
+        if (persistentEntity.getPropertyByName(propertyName) == null) {
+            throw new IllegalArgumentException("Property [$propertyName] is 
not a valid property of ${persistentEntity.name}")
+        }
+        return propertyName
+    }

Review Comment:
   Addressed in `00b1e05ce4`: `validateWherePropertyName` now rejects mapped 
target/column aliases by requiring the resolved persistent property name to 
exactly match the requested key. Added 
`HibernateGormStaticApiMappedPropertyEntity.findWhere(name_col: ...)` coverage 
to lock the behavior.



-- 
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]

Reply via email to