Blazebit / blaze-persistence

Rich Criteria API for JPA providers
https://persistence.blazebit.com
Apache License 2.0
727 stars 85 forks source link

Binding "NULL" for CTE attributes not working #992

Closed Mobe91 closed 4 years ago

Mobe91 commented 4 years ago

I have a CTE query like

builder.withRecursive(ArticleTreeNodeCte.class)
                    .from(ArticleTreeNode .class, "startNode")
                    .bind("attributeValues").select("NULL")

where attributeValues is an attribute of type Map<UUID, Object>.

With blaze-persistence 1.4.1 I get the following exception for this query.

org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.QueryException: No data type for node: org.hibernate.hql.internal.ast.tree.MethodNode 
 \-[METHOD_CALL] MethodNode: 'FUNCTION (CAST_Map)'
    +-[METHOD_NAME] IdentNode: 'CAST_Map' {originalText=CAST_Map}
    \-[EXPR_LIST] SqlNode: 'exprList'
       +-[NULL] NullNode: 'NULL'
       \-[QUOTED_STRING] LiteralNode: ''uuid''
 [SELECT startNode.id, startNode.id, startNode.parent.id, 0, FUNCTION('CAST_Map',NULL,'uuid') FROM com.ordami.common.domain.entity.articles.ArticleTreeNode startNode WHERE startNode.id IN (:param_0)]; nested exception is java.lang.IllegalArgumentException: org.hibernate.QueryException: No data type for node: org.hibernate.hql.internal.ast.tree.MethodNode 
 \-[METHOD_CALL] MethodNode: 'FUNCTION (CAST_Map)'
    +-[METHOD_NAME] IdentNode: 'CAST_Map' {originalText=CAST_Map}
    \-[EXPR_LIST] SqlNode: 'exprList'
       +-[NULL] NullNode: 'NULL'
       \-[QUOTED_STRING] LiteralNode: ''uuid''
 [SELECT startNode.id, startNode.id, startNode.parent.id, 0, FUNCTION('CAST_Map',NULL,'uuid') FROM com.ordami.common.domain.entity.articles.ArticleTreeNode startNode WHERE startNode.id IN (:param_0)]

This affects version 1.4.1 and used to work with previous versions.

jwgmeligmeyling commented 4 years ago

Hmm it must be due to the change for #781

I remember you experienced the exact same bug before, but I can't find it anymore. (I thought we should have had a test case for this usage)

jwgmeligmeyling commented 4 years ago

Ah nvm, that issue was regarding expanding bindings for embeddables and is still unresolved #567

jwgmeligmeyling commented 4 years ago

@Mobe91 What is the type / mapping for attributeValues? I can't reproduce this with a simple basic type.

Mobe91 commented 4 years ago

@jwgmeligmeyling Sorry, should have mentioned that the attributeValues attribute is stored as json.

@Type(type = "json", parameters = @org.hibernate.annotations.Parameter(name = "useJsonTypeInfo", value = "true"))
private Map<UUID, Object> attributeValues;
jwgmeligmeyling commented 4 years ago

Already thought so, thanks for confirming!

jwgmeligmeyling commented 4 years ago

I have a tentative fix in https://github.com/Blazebit/blaze-persistence/compare/master...jwgmeligmeyling:issues/992?expand=1 .

I'll open the PR when the test run has passed.