-->
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.  [ 2 posts ] 
Author Message
 Post subject: JPQL - Limiting Joined Inheritance Tables
PostPosted: Wed Mar 09, 2011 11:19 pm 
Beginner
Beginner

Joined: Wed Nov 21, 2007 10:24 am
Posts: 25
I've got a lot of tables that are subclasses of a type with @Inheritance(strategy = InheritanceType.JOINED), but the problem is when I try to do a JPQL query to just one type using a query like
Code:
select value from value join value." + valueName + " dbValue " + " where value.class=" + valueClazz.getName() + " AND dbValue=?

it tries to join all inherited tables and uses a really complex where statement:
Code:
where case when value1_1_.id is not null then 1 when value1_2_.id is not null then 2 when value1_3_.id is not null then 3 when value1_4_.id is not null then 4 when value1_5_.id is not null then 5 when value1_6_.id is not null then 6 when value1_7_.id is not null then 7 when value1_8_.id is not null then 8 when value1_9_.id is not null then 9 when value1_10_.id is not null then 10 when value1_11_.id is not null then 11 when value1_12_.id is not null then 12 when value1_13_.id is not null then 13 when value1_14_.id is not null then 14 when value1_15_.id is not null then 15 when value1_16_.id is not null then 16 when value1_17_.id is not null then 17 when value1_18_.id is not null then 18 when value1_19_.id is not null then 19 when value1_20_.id is not null then 20 when value1_21_.id is not null then 21 when value1_22_.id is not null then 22 when value1_23_.id is not null then 23 when value1_24_.id is not null then 24 when value1_25_.id is not null then 25 when value1_26_.id is not null then 26 when value1_27_.id is not null then 27 when value1_28_.id is not null then 28 when value1_29_.id is not null then 29 when value1_30_.id is not null then 30 when value1_31_.id is not null then 31 when value1_32_.id is not null then 32 when value1_33_.id is not null then 33 when value1_34_.id is not null then 34 when value1_35_.id is not null then 35 when value1_36_.id is not null then 36 when value1_37_.id is not null then 37 when value1_38_.id is not null then 38 when value1_39_.id is not null then 39 when value1_40_.id is not null then 40 when value1_41_.id is not null then 41 when value1_42_.id is not null then 42 when value1_43_.id is not null then 43 when value1_44_.id is not null then 44 when value1_45_.id is not null then 45 when value1_46_.id is not null then 46 when value1_47_.id is not null then 47 when value1_48_.id is not null then 48 when value1_49_.id is not null then 49 when value1_50_.id is not null then 50 when value1_51_.id is not null then 51 when value1_52_.id is not null then 52 when value1_53_.id is not null then 53 when value1_54_.id is not null then 54 when value1_55_.id is not null then 55 when value1_56_.id is not null then 56 when value1_57_.id is not null then 57 when value1_58_.id is not null then 58 when value1_59_.id is not null then 59 when value1_60_.id is not null then 60 when value1_61_.id is not null then 61 when value1_62_.id is not null then 62 when value1_63_.id is not null then 63 when value1_64_.id is not null then 64 when value1_65_.id is not null then 65 when value1_66_.id is not null then 66 when value1_67_.id is not null then 67 when value1_68_.id is not null then 68 when value1_69_.id is not null then 69 when value1_70_.id is not null then 70 when value1_71_.id is not null then 71 when value1_72_.id is not null then 72 when value1_73_.id is not null then 73 when value1_74_.id is not null then 74 when value1_75_.id is not null then 75 when value1_76_.id is not null then 76 when value1_77_.id is not null then 77 when value1_78_.id is not null then 78 when value1_79_.id is not null then 79 when value1_80_.id is not null then 80 when value1_81_.id is not null then 81 when value1_82_.id is not null then 82 when value1_83_.id is not null then 83 when value1_84_.id is not null then 84 when value1_85_.id is not null then 85 when value1_86_.id is not null then 86 when value1_87_.id is not null then 87 when value1_88_.id is not null then 88 when value1_89_.id is not null then 89 when value1_90_.id is not null then 90 when value1_91_.id is not null then 91 when value1_92_.id is not null then 92 when value1_93_.id is not null then 93 when value1_94_.id is not null then 94 when value1_95_.id is not null then 95 when value1_96_.id is not null then 96 when value1_97_.id is not null then 97 when value1_98_.id is not null then 98 when value1_99_.id is not null then 99 when value1_100_.id is not null then 100 when value1_101_.id is not null then 101 when value1_102_.id is not null then 102 when value1_103_.id is not null then 103 when value1_104_.id is not null then 104 when value1_105_.id is not null then 105 when value1_106_.id is not null then 106 when value1_107_.id is not null then 107 when value1_108_.id is not null then 108 when value1_109_.id is not null then 109 when value1_110_.id is not null then 110 when value1_111_.id is not null then 111 when value1_112_.id is not null then 112 when value1_113_.id is not null then 113 when value1_114_.id is not null then 114 when value1_115_.id is not null then 115 when value1_116_.id is not null then 116 when value1_117_.id is not null then 117 when value1_118_.id is not null then 118 when value1_119_.id is not null then 119 when value1_120_.id is not null then 120 when value1_121_.id is not null then 121 when value1_122_.id is not null then 122 when value1_123_.id is not null then 123 when value1_124_.id is not null then 124 when value1_125_.id is not null then 125 when value1_126_.id is not null then 126 when value1_127_.id is not null then 127 when value1_128_.id is not null then 128 when value1_129_.id is not null then 129 when value1_130_.id is not null then 130 when value1_131_.id is not null then 131 when value1_132_.id is not null then 132 when value1_133_.id is not null then 133 when value1_134_.id is not null then 134 when value1_135_.id is not null then 135 when value1_136_.id is not null then 136 when value1_137_.id is not null then 137 when value1_138_.id is not null then 138 when value1_139_.id is not null then 139 when value1_140_.id is not null then 140 when value1_141_.id is not null then 141 when value1_142_.id is not null then 142 when value1_143_.id is not null then 143 when value1_144_.id is not null then 144 when value1_145_.id is not null then 145 when value1_146_.id is not null then 146 when value1_147_.id is not null then 147 when value1_148_.id is not null then 148 when value1_149_.id is not null then 149 when value1_150_.id is not null then 150 when value1_151_.id is not null then 151 when value1_152_.id is not null then 152 when value1_153_.id is not null then 153 when value1_154_.id is not null then 154 when value1_155_.id is not null then 155 when value1_156_.id is not null then 156 when value1_.id is not null then 0 end=48


Unfortunately the number of sub-tables is also greater than the max MySQL can join off of by default so I get an error when it tries to execute the query. How can I make it just use the one table it needs for the class I've specified? I've tried TYPE(value) too, but that did the same thing. If I add a @DiscriminatorColumn with an @DiscriminatorValue on each subclass, will that make it use the right table or will it still try and join all these?


Top
 Profile  
 
 Post subject: Re: JPQL - Limiting Joined Inheritance Tables
PostPosted: Thu Mar 10, 2011 1:01 am 
Beginner
Beginner

Joined: Wed Nov 21, 2007 10:24 am
Posts: 25
Figured it out somewhat, I just restructured the query to use a cross join:
Code:
select link from CommentLink link, " + valueClazz.getName() + " value where link.parent=value AND value." + valueName + "=?


I had taken the first part off in the paste of my first query for the "CommentLink" portion, but it seems ridiculous that it doesn't figure out which tables it actually needs if you specify which class type you want in the WHERE portion. Otherwise it's just joining tables only to eliminate them in that huge case statement. "CommentLink" has a link to my generic abstract "Value" class, but in my example it will always go for a specific subclass that's just unknown and I don't want to have a lot of foreign keys in my CommentLink table (in fact it already fails if I don't do a JOINED inheritance for subclasses of Value due to limit of foreign keys for MySQL).


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.