-->
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: CriteriaBuilder + Inheritance
PostPosted: Thu May 02, 2013 5:16 am 
Newbie

Joined: Tue Apr 16, 2013 2:48 pm
Posts: 2
Hi

Can the Criteria API / CriteriaBuilder be used with Inheritance/Polymorphism? e.g.

entity A
valueA
entity B extends A
valueB
entity C extends A
valueC

When I select entity A in JP-QL, I have automatically access to the attributes valueA, valueB and valueC and they are null if a given object does not belong the the corresponding subtype. This allows to to create queries returning all three types of objects and specifying filters on any of the properties.

With the CriteriaBuilder this does not work since it is strongly typed:
root = criteriaQuery.from(A.class)
criteriaQuery.select(root.get("valueB"))

Naturally, I could use from(B.class), but then I would loose the ability to return all three types of objects in a single query.
Or is there at any possibility to specify an outer/left join to the subtypes so that I could access the child properties trough the join?

With JPA 2.1 there will be a "TREAT AS ..." feature which does exactly that.

Thanks, Regards
Remo


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.