0

I have try this one in many ways finally i found a way but it is not working on linux environment following HQL is that

SELECT es.eventId as eventId, MAX(es.raisedTimestamp) as raisedTimestamp, es.id as id, es.isReset as isReset FROM EsEvent es WHERE es.isReset=1 GROUP BY es.eventId ORDER BY es.raisedTimestamp DESC

this will end up with the enabled ONLY_FULL_GROUP_BY mode in mysql.

so that i added ANY_VALUE() function to my hql below one is that.

SELECT es.eventId as eventId, MAX(es.raisedTimestamp) as raisedTimestamp, ANY_VALUE(es.id) as id, es.isReset as isReset FROM EsEvent es WHERE es.isReset=1 GROUP BY es.eventId ORDER BY ANY_VALUE(es.raisedTimestamp) DESC

in this case it will end up with HQL exception like this

Failed to create sessionFactory object: java.lang.IllegalStateException: No data type for node: org.hibernate.hql.internal.ast.tree.MethodNode +-[METHOD_CALL] MethodNode: '('|  +-[METHOD_NAME] IdentNode: 'ANY_VALUE' {originalText=ANY_VALUE}|  \-[EXPR_LIST] SqlNode: 'exprList'|     \-[DOT] DotNode:'esevent0_.ID'{propertyName=id,dereferenceType=PRIMITIVE,getPropertyPath=id,path=es.id,tableAlias=esevent0_,className=org.reactor.monitoring.model.entity.EsEvent,classAlias=es}|        +-[ALIAS_REF] IdentNode: 'esevent0_.ID' {alias=es, className=org.reactor.monitoring.model.entity.EsEvent, tableAlias=esevent0_} |        \-[IDENT] IdentNode: 'id' {originalText=id}

please any one can help me to fix this out. it is really helpful and if you can give me reason behind this it's highly appreciate.

randikaisuru
  • 81
  • 1
  • 14

1 Answers1

1

You can't use ANY_VALUE() with HQL.

But you can

  1. Use it with the native SQL https://www.mkyong.com/hibernate/hibernate-native-sql-queries-examples/
  2. Add ANY_VALUE() as the custom function to HQL How to use native sql function with HQL query?
v.ladynev
  • 19,275
  • 8
  • 46
  • 67