Hello, I have this code which worked perfectly with eclipselink JPA implementation.
CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder(); CriteriaQuery<Tuple> criteriaQuery = criteriaBuilder.createTupleQuery(); Root<VistaFile> from = criteriaQuery.from(MyTable.class);
Predicate p = buildPredicate();
Expression<String> indexName = "myIndex"; Expression<Long> textkey = from.get("id").as(Long.class); Expression<String> textQuery = criteriaBuilder.literal("health"); Expression<String> startTag = criteriaBuilder.literal("<b>"); Expression<String> endTag = criteriaBuilder.literal("</b>");
Expression<String> snippet = criteriaBuilder.function("CTX_DOC.snippet", String.class, indexName, textkey, textQuery, startTag, endTag);
criteriaQuery.multiselect(from, snippet );
criteriaQuery.where(p);
TypedQuery<Tuple> createdQuery = em.createQuery(criteriaQuery); List<Tuple> results = createdQuery.getResultList();
As soon as I switch to hibernate I had this exception:
java.lang.IllegalStateException: No data type for node: org.hibernate.hql.ast.tree.MethodNode \-[METHOD_CALL] MethodNode: '(' +-[METHOD_NAME] IdentNode: 'CTX_DOC.snippet' {originalText=CTX_DOC.snippet} \-[EXPR_LIST] SqlNode: 'exprList' +-[NAMED_PARAM] ParameterNode: '?' {name=param0, expectedType=null} +-[DOT] DotNode: 'vistafile0_.id' {propertyName=id,dereferenceType=ALL,propertyPath=id,path=generatedAlias0.id,tableAlias=vistafile0_,className=eu.ec.vista.model.document.VistaFile,classAlias=generatedAlias0} | +-[ALIAS_REF] IdentNode: 'vistafile0_.id' {alias=generatedAlias0, className=eu.ec.vista.model.document.VistaFile, tableAlias=vistafile0_} | \-[IDENT] IdentNode: 'id' {originalText=id} +-[NAMED_PARAM] ParameterNode: '?' {name=param1, expectedType=null} +-[NAMED_PARAM] ParameterNode: '?' {name=param2, expectedType=null} \-[NAMED_PARAM] ParameterNode: '?' {name=param3, expectedType=null}
at org.hibernate.hql.ast.tree.SelectClause.initializeExplicitSelectClause(SelectClause.java:156) at org.hibernate.hql.ast.HqlSqlWalker.useSelectClause(HqlSqlWalker.java:852) at org.hibernate.hql.ast.HqlSqlWalker.processQuery(HqlSqlWalker.java:640) at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:685) at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:301) at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:244) at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:254) at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185) at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
Anybody knows how to solve it?
|