-->
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.  [ 1 post ] 
Author Message
 Post subject: JPA 2.0 Typed CriteriaQuery problem with ListJoin.index()
PostPosted: Tue Oct 09, 2012 12:14 am 
Newbie

Joined: Mon Apr 04, 2011 12:10 pm
Posts: 1
Hi Everyone,

I was wondering if I found a bug or I'm just doing something incorrectly. I have a query that relies on the index value of an ordered collection of elements. I've been trying to use Criteria api with the JPA metamodel for all my queries, but I'm getting a strange error with my index query. Here is a simple example:

Parent:
Code:
@Entity
public class Parent implements Serializable {

   @Id
   private Long id;

   @ElementCollection
   @CollectionTable(joinColumns = @JoinColumn(name = "parent_id"))
   @OrderColumn
   private List<Embed> embeds = new ArrayList<Embed>();
// not including getters and setters for brevity
}


Child:
Code:
@Embeddable
public class Embed implements Serializable {

   private static final long serialVersionUID = 1L;

   private Long prop1;

   private Long prop2;
   // not including getters and setters for brevity
}


This query works fine:

Code:
return em.createQuery("select p from Parent p inner join p.embeds e where index(e) > 0", Parent.class).getResultList();


This one doesn't. Am I using ListJoin.index() incorrectly?

Code:
      CriteriaBuilder cb = em.getCriteriaBuilder();
      CriteriaQuery<Parent> criteria = cb.createQuery(Parent.class);
      Root<Parent> parent = criteria.from(Parent.class);
      ListJoin<Parent, Embed> embeds = parent.join(Parent_.embeds);
      criteria.where(cb.ge(embeds.index(), 0));
      return em.createQuery(criteria).getResultList();


I tried changing Embed to an actual Entity and using @OneToMany instead of @ElementCollection, but I got the same exception. Here is the stacktrace I get is below. It seems like the problem is with the code that converts the criteria query to hql. Oh, and I'm using the hibernate version that ships with JBoss as 7.1.1.Final. Any ideas for another way I could write this query?

Code:
Caused by: org.hibernate.QueryException: could not resolve property: embeds of: component[prop1,prop2] [select generatedAlias0 from com.verifi.verifiweb.service.Parent as generatedAlias0 inner join generatedAlias0.embeds as generatedAlias1 where index(generatedAlias1.embeds)>=0]
   at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:83) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
   at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:77) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
   at org.hibernate.persister.collection.AbstractCollectionPersister.toType(AbstractCollectionPersister.java:1486) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
   at org.hibernate.hql.internal.ast.tree.FromElementType.getPropertyType(FromElementType.java:313) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
   at org.hibernate.hql.internal.ast.tree.FromElement.getPropertyType(FromElement.java:485) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
   at org.hibernate.hql.internal.ast.tree.DotNode.getDataType(DotNode.java:598) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
   at org.hibernate.hql.internal.ast.tree.DotNode.prepareLhs(DotNode.java:266) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
   at org.hibernate.hql.internal.ast.tree.DotNode.resolveInFunctionCall(DotNode.java:188) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
   at org.hibernate.hql.internal.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:880) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
   at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1246) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
   at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4252) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
   at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.functionCall(HqlSqlBaseWalker.java:2429) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
   at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1320) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
   at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4252) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
   at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3850) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
   at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1923) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
   at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:782) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
   at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:583) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
   at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:287) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
   at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:235) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
   at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:248) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
   at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
   at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
   at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:101) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
   at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:80) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
   at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:119) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
   at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:214) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
   at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:192) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
   at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1537) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
   at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:487) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
   ... 177 more


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

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.