Support KEY, ENTRY and VALUE qualifiers in WHERE clause

Attachments

1
  • 06 Jun 2012, 08:24 PM

Activity

Show:

Raivis Kalinins July 6, 2012 at 2:58 PM

Upgraded to 4.1.5-SNAPSHOT and tried to run this query:

select count(r.id) from Record r
join r.address a
join a.country c
join c.countryTexts ct
where key(ct) = 'en' and value(ct) like '%Swed%'

which generates this query:

select count(recor0_.id) as col_0_0_ from record recor0_
inner join address address1_ on recor0_.address_id=address1_.id
inner join country country2_ on address1_.country_id=country2_.country_id
inner join country_text countrytex3_ on country2_.country_id=countrytex3_.country_id
where countrytex3_.locale='en' and ((select countrytex3_.country_text from country_text countrytex3_ where country2_.country_id=countrytex3_.country_id) like '%Swed%') limit ?

and then we obviously get cardinality violation error cause of the subquery
Is this how it should be?
I mean why is there a subquery instead of simply "countrytex3_.country_text" which is the value of the map?

@ElementCollection
@CollectionTable(name = "country_text", joinColumns = @JoinColumn(name = "country_id"))
@MapKeyColumn(name = "locale")
@Column(name = "country_text")
private Map<Locale, String> countryTexts = new HashMap<Locale, String>();

Steve Ebersole June 6, 2012 at 9:56 PM

The case has NOTHING to do with it. It is simply not recognized as a structural part of the query; aka it is not recognized as fulfilling the role of the JPA keyword in that context. That is the issue. Because the translator does not recognize the term as a keyword it attempts to resolve it in other means. Both JPQL and HQL are only case insensitive in regards to keywords; other aspects of the query are indeed case-sensitive. So again, this has nothing to do with case sensitivity. Please stop muddying the waters here with inaccurate assumptions and analysis. It just confuses people who come after looking at the issues.

Harald Wellmann June 6, 2012 at 8:41 PM

Attached is a test case. Unpack and run mvn clean test to see 2 of 3 tests fail. Run mvn -Popenjpa clean test to see all tests pass on OpenJPA.

There are two more ignored tests without an alias reference in KEY() which are supposed to work according to the comments in https://hibernate.atlassian.net/browse/HHH-5396#icft=HHH-5396 but do not.
Anyway, this is illegal syntax according to JSR-317 section 4.4.4: the KEY operator accepts an identification variable and not a general path expression.

The two tests with the KEY operator in lower case and in upper case also demonstrate that Hibernate is not case insensitive in this context, as noted by myself and confirmed by Yannick Lazzari in the original issue HHH-5396.

Fixed

Details

Assignee

Reporter

Time tracking

4.97h logged

Fix versions

Priority

Created June 6, 2012 at 6:57 PM
Updated July 12, 2012 at 9:10 AM
Resolved June 7, 2012 at 12:23 AM