-->
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: Access subclass properties in Criteria Builder JPA
PostPosted: Thu Aug 22, 2013 7:53 pm 
Newbie

Joined: Mon Aug 19, 2013 9:37 pm
Posts: 2
I am trying to use the JPA 2.0's criteria query with the underlying implementation of Hibernate. I am having issues while trying to access properties of subclass in the where clause..

Following are brief description of the entities:

- Class A (which is a Entity & a Table by itself)
- Class B (which is a Entity & a Table by itself)
- Class A has OneToMany relationship with B
- Class AB & BA are child classes of B (Both are entities but are not mapped to any tables. It holds few properties specific to it.)
- Let us suppose both classes AB & BA has a property '''symbol'''

Now comes the criteria query:

CriteriaBuilder qb = futuresEntityManager.getCriteriaBuilder();
CriteriaQuery<A> query = qb.createQuery(A.class);
Root<A> a = query.from(A.class);
Join<A,B> b = a.joinSet("aLegs", JoinType.INNER);

Now when I form the predicates:

predicate=qb.and(qb.equal(a.get("id").get("accountId"), "1234"));
predicate=qb.and(predicate,b.get("symbol").in(input.getSymbol()));
----- The above line does not work at run time as b does not hold the reference to symbol. only child classes AB & BA holds it..

How do i access the properties of child classes in this query ? I have to Include both AB & BA for the symbol predicate.

Can anybody help me to resolve this issue ?


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.