There is a query I use to get a list of countries based on a substring.
It runs well with Hibernate 5 but when I switch to the latest 6 Alpha9, I get an error.
@Query(
"SELECT DISTINCT country " +
"FROM Country country " +
"LEFT JOIN FETCH country.localizations.data loc " +
"WHERE " +
"LOWER( country.nativeName ) LIKE LOWER( :name ) " +
"OR ( " +
"KEY( loc ) LIKE 'NAME%' " +
"AND " +
"LOWER( loc ) LIKE LOWER( :name ) " +
// "LOWER( VALUE( loc ) ) LIKE LOWER( :name ) " +
")"
)
List<Country> findBySubstring(@Param(value = "name") String name);
Country entity has Localizations object which has its own Map<String, String> called ādataā. The key can be āNAME . ENā, NAME . DE", āDESCRIPTION . ENā, āDESCRIPTION . DEā (no spaces but this editor shows it as www domain name) and so on, and the value is a country name or description or something else depending on the key prefix.
The error I get with 6:
Caused by: java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List com.thevegcat.app.entities.country.repository.CountryRepository.findBySubstring(java.lang.String)!
...
Caused by: java.lang.IllegalArgumentException: org.hibernate.query.sqm.InterpretationException: Error interpreting query [SELECT DISTINCT country FROM Country country LEFT JOIN FETCH country.localizations.data loc WHERE LOWER( country.nativeName ) LIKE LOWER( :name ) OR ( KEY( loc ) LIKE 'NAME%' AND LOWER( loc ) LIKE LOWER( :name ) )]; this may indicate a semantic (user query) problem or a bug in the parser
...
Caused by: org.hibernate.query.sqm.InterpretationException: Error interpreting query SELECT DISTINCT country FROM Country country LEFT JOIN FETCH country.localizations.data loc WHERE LOWER( country.nativeName ) LIKE LOWER( :name ) OR ( KEY( loc ) LIKE 'NAME%' AND LOWER( loc ) LIKE LOWER( :name ) )]; this may indicate a semantic (user query) problem or a bug in the parser
...
Caused by: java.lang.ClassCastException: class org.hibernate.metamodel.model.domain.internal.MapAttributeImpl cannot be cast to class org.hibernate.metamodel.model.domain.AllowableFunctionReturnType (org.hibernate.metamodel.model.domain.internal.MapAttributeImpl and org.hibernate.metamodel.model.domain.AllowableFunctionReturnType are in unnamed module of loader 'app')
Is there something Iām missing / doing wrong or can it be a bug in Hibernate 6?