-->
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-Query type-operator fails on H2-Database
PostPosted: Mon Jun 08, 2015 8:59 am 
Newbie

Joined: Mon Jun 08, 2015 8:45 am
Posts: 2
Given is the following JPQL-Query:
Code:
from AddressVersion a where type(a) = AddressInhouse


AddressInhouse is a subclass from AddressVersion.

The following error occurs:

Quote:
Caused by: org.h2.jdbc.JdbcSQLException: Feld "DOMESTIC" nicht gefunden
Column "DOMESTIC" not found;


The generated SQL, handling the type-operator, on H2-Database is:

Quote:
from
ADDRESS_VER addressver0_
left outer join
ADDRESS_DOMESTIC addressver0_1_
on addressver0_.ADDRV_ID=addressver0_1_.ADDO_ADDRV_ID
left outer join
ADDRESS_FOREIGN addressver0_2_
on addressver0_.ADDRV_ID=addressver0_2_.ADFO_ADDRV_ID
left outer join
ADDRESS_INHOUSE addressver0_3_
on addressver0_.ADDRV_ID=addressver0_3_.ADIH_ADDRV_ID
where
case
when addressver0_1_.ADDO_ADDRV_ID is not null then DOMESTIC
when addressver0_2_.ADFO_ADDRV_ID is not null then FOREIGN
when addressver0_3_.ADIH_ADDRV_ID is not null then INHOUSE

when addressver0_.ADDRV_ID is not null then 'AddressVersion'
end='INHOUSE'


However, the discriminator-values in the case-statement should be treated as String (in hyphens)
Quote:
when addressver0_1_.ADDO_ADDRV_ID is not null then 'DOMESTIC'
when addressver0_2_.ADFO_ADDRV_ID is not null then 'FOREIGN'
when addressver0_3_.ADIH_ADDRV_ID is not null then 'INHOUSE'

when addressver0_.ADDRV_ID is not null then 'AddressVersion'
end='INHOUSE'


Looks for me like a bug in the H2-Dialect.
Can somebody confirm this or give me some advice?

Thanks


Top
 Profile  
 
 Post subject: Re: JPQL-Query type-operator fails on H2-Database
PostPosted: Wed Jun 10, 2015 9:20 am 
Newbie

Joined: Mon Jun 08, 2015 8:45 am
Posts: 2
I found a workaround:

Use a numeric-field and numeric-values for the discriminator:
Code:
@DiscriminatorColumn(name = "TYPE", discriminatorType = DiscriminatorType.INTEGER)
@DiscriminatorValue("0")


This will generate valid SQL when the type-operator is used.

Remark: This limitation is not only for H2-dialect as posted above. I reproduced it as well on Oracle.


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.