-->
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: Inheritance Joined Criteria Queryies to subclasses
PostPosted: Mon Oct 31, 2011 8:52 pm 
Newbie

Joined: Mon Oct 31, 2011 8:46 pm
Posts: 3
Hi I have been trying to figure this out and cant. If I have the following

class d
Class ad extends d
d has a reference to t as getT();
class T
Class a extends T
class p extends T

How can I write a criteria query to go into a. I can do

CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
CriteriaQuery query = cb.createQuery(ad.class);
Root fromType = query.from(ad.class);
cb.equal(fromType.get("t"),get("id"), "test");

Since id is in t that's no problem but lets say bank is in a I get error if I do
cb.equal(fromType.get("t").get("bank"), "test");

I can't do
cb.equal(fromType.get("t").as(a.class).get("bank"), "test");
either because as returns sum CastFunction which I can't figure out what to do with.


Anyway is this possible seems like would be pretty common use case.

By the way this JPQL query does work
"SELECT apd FROM apd apd, t p, a ap WHERE apd.t.id = p.id AND apd.t.id = ap.id"

So just need to get this functionality in criteria api if possible.


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.