Query not working anymore

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?

This is probably a bug in Hibernate 6.0. We would appreciate if you could provide a reproducer for this. You can work with e.g. hibernate-test-case-templates/JPAUnitTestCase.java at main Ā· hibernate/hibernate-test-case-templates Ā· GitHub to provide this reproducer. If possible, create an issue on JIRA (https://hibernate.atlassian.net) and attach the reproducer.

1 Like

There is my other ticket regarding permanent lack of success trying to sign in into Jira.

Yeah, sorry about the trouble you are having here. I hope the Atlassian support can help you. You can also post the reproducer here if you want and I will create the issue for you.

1 Like

Hi Christian!
Today I created a small project having all needed to get this behaviour. Please is there a chance to add you as a user on my BitBucket to avoid making it public?
BR,
Hrvoje

Sure, share it with me. My username is cbeikov

Tried to do so, but not sure it went well. Asked me for email so I assumed @gmail.com is the one.
While typing your username only, without @gmail.com - confirm button was disabled.

Ok, I finally took a look at your example, but switching to the latest Hibernate 6 version isnā€™t easy because of the Jakarta namespace switch. Anyway, we have re-enabled an internal test in Hibernate that looks similar to the one you have here and was fixed with 6.0.0.Beta2, so I think this should not be a problem anymore. Thanks for the test!