-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: criteriaBuilder function throws No data type for node: org.h
PostPosted: Fri Jan 28, 2011 9:41 am 
Newbie

Joined: Fri Jan 28, 2011 9:31 am
Posts: 2
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?


Top
 Profile  
 
 Post subject: Re: criteriaBuilder function throws No data type for node: org.h
PostPosted: Fri Jan 28, 2011 12:13 pm 
Newbie

Joined: Fri Jan 28, 2011 9:31 am
Posts: 2
I don't like the way I solved it.

I added this line

Expression<String> snippet2 = criteriaBuilder.function("TO_CHAR", String.class, snippet);

and I change this

criteriaQuery.multiselect(from, snippet2 /* , score */);

Any suggestion to set the returned data type to a string?
thx


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.