-->
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.  [ 3 posts ] 
Author Message
 Post subject: Cast string to number using JPA2 Criteria
PostPosted: Thu Feb 23, 2012 2:58 am 
Newbie

Joined: Wed Nov 03, 2010 2:36 pm
Posts: 9
Hello, I am trying to write a query with subselect where a string is casted to a long.

Query is below, where EntityKeyword_.relatedToId is a String type SingularAttribute

Code:
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Task> query = cb.createQuery(Task.class);
   
Root<Task> from = query.from(Task.class);
   
Subquery<Long> subquery = query.subquery(Long.class);
Root<EntityKeyword> fromKeyword = subquery.from(EntityKeyword.class);
subquery.select(fromKeyword.get(EntityKeyword_.relatedToId).as(Long.class));
subquery.where(cb.like(fromKeyword.get(EntityKeyword_.keyword), term));
   
query.where(cb.in(from.get(ModelEntity_.id)).value(subquery));


But it fails with exception:

Code:
    Last cause: No data type for node: org.hibernate.hql.ast.tree.MethodNode
     \-[METHOD_CALL] MethodNode: '('
        +-[METHOD_NAME] IdentNode: 'cast' {originalText=cast}
        \-[EXPR_LIST] SqlNode: 'exprList'
           +-[DOT] DotNode: 'entitykeyw1_.keyword' {propertyName=keyword,dereferenceType=ALL,propertyPath=keyword,path=generatedAlias1.keyword,tableAlias=entitykeyw1_,className=l.i.s.m.s.EntityKeyword,classAlias=generatedAlias1}
           |  +-[ALIAS_REF] IdentNode: 'entitykeyw1_.id' {alias=generatedAlias1, className=l.i.s.m.s.EntityKeyword, tableAlias=entitykeyw1_}
           |  \-[IDENT] IdentNode: 'keyword' {originalText=keyword}
           \-[IDENT] IdentNode: 'int8' {originalText=int8}


I'm using Hibernate 3.6.8-Final and don not have I slightest idea what's wrong...


Top
 Profile  
 
 Post subject: Re: Cast string to number using JPA2 Criteria
PostPosted: Thu Feb 23, 2012 9:52 am 
Newbie

Joined: Wed Nov 03, 2010 2:36 pm
Posts: 9
It seems that hibernate can't resolve return type using type resolver...
That's all I got...

Type name is "int8" from PostgreSQLDialect and when it looks in basic type registry in TypeResolver - nothing can be found...

No idea what to do next...


Top
 Profile  
 
 Post subject: Re: Cast string to number using JPA2 Criteria
PostPosted: Mon Feb 27, 2012 9:04 am 
Newbie

Joined: Wed Nov 03, 2010 2:36 pm
Posts: 9
Still looking for an answer...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.