# JPQL FUNCTION call not working in LIKE

**URL:** <https://discourse.hibernate.org/t/jpql-function-call-not-working-in-like/11822>\
**Category:** Hibernate ORM\
**Created:** [October 10, 2025, 2:01pm UTC](https://discourse.hibernate.org/t/jpql-function-call-not-working-in-like/11822 "2025-10-10T14:01:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ghislain-rouvignac\_f](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/ghislain-rouvignac_f/32/4149_2.png) [@ghislain-rouvignac\_f](https://discourse.hibernate.org/u/ghislain-rouvignac_f)\
**Post date:** [October 10, 2025, 2:01pm UTC](https://discourse.hibernate.org/t/jpql-function-call-not-working-in-like/11822/1 "2025-10-10T14:01:08Z")

</div>

Hello,

With HIbernate 6.6, I have an issue when calling JPQL FUNCTION in LIKE.

The following test fails with error: `org.hibernate.query.SemanticException: Operand of 'like' is of type 'java.lang.Object' which is not a string (its JDBC type code is not string-like)`

```java
package org.hibernate.orm.test.query.hql;

import org.hibernate.Session;
import org.hibernate.orm.test.jpa.model.AbstractJPATest;
import org.junit.jupiter.api.Test;

/**
 * Test use of like with functions
 *
 */
public class FunctionAndLikeJPQLTest extends AbstractJPATest {

	@Test

	public void functionSubstrLikeTest() {
		try (Session session = this.sessionFactoryScope().getSessionFactory().openSession()) {
			// Assertions.assertThrows(IllegalArgumentException.class, () -> {
			session.createQuery("select i from Item i where function( 'substr', i.name, 1, 3 ) like 'abc'")
					.list();
			// });
		}
	}

	@Test
	public void likeFunctionSubstrTest() {
		try (Session session = this.sessionFactoryScope().getSessionFactory().openSession()) {
			// Assertions.assertThrows(IllegalArgumentException.class, () -> {
			session.createQuery("select i from Item i where 'abc' like function( 'substr', i.name, 1, 3 )")
					.list();
			// });
		}
	}
}

```

Per JPA spec, at least `functionSubstrLikeTest` should work, I am not sure about `likeFunctionSubstrTest`

The test fails from hibernate branches 6.6, 7.1 to main branch.

Regards

---

<div class="post-metadata">

**Author:** ![mbladel](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mbladel/32/2128_2.png) [@mbladel](https://discourse.hibernate.org/u/mbladel)\
**Post date:** [October 15, 2025, 1:37pm UTC](https://discourse.hibernate.org/t/jpql-function-call-not-working-in-like/11822/2 "2025-10-15T13:37:57Z")

</div>

Hello @ghislain-rouvignac_f, why are you using a custom `function()` expression instead of Hibernate’s [standard](https://docs.hibernate.org/orm/current/userguide/html_single/#hql-string-functions) `substring()`? Anyway, if you really need to do that, you should be able to easily workaround that by using `cast(function(...) as String)` in your `like` expression.

---

<div class="post-metadata">

**Author:** ![ghislain-rouvignac\_f](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/ghislain-rouvignac_f/32/4149_2.png) [@ghislain-rouvignac\_f](https://discourse.hibernate.org/u/ghislain-rouvignac_f)\
**Post date:** [October 16, 2025, 6:48am UTC](https://discourse.hibernate.org/t/jpql-function-call-not-working-in-like/11822/3 "2025-10-16T06:48:09Z")

</div>

Hello @mbladel,

In my case I have the problem with a custom function registered in the `Dialect`.  
In the unit test, I used `substr` as an example to easily build the test.  
This problem is reproducible with any `String` manipulating function.  
I want to be strict JPQL compliant this is why I use `FUNCTION`.

I know that I can workaround with `cast(function(...) as String)` but my purpose is to highlight a bug.

Per JPA spec:

```plaintext
like_expression ::= string_expression [NOT] LIKE pattern_value [ESCAPE escape_character]

string_expression ::=
    state_valued_path_expression |
    string_literal |
    input_parameter |
    functions_returning_strings |
    aggregate_expression |
    case_expression |
    function_invocation |
    string_cast_function |
    string_expression || string_expression |
    (subquery)

function_invocation ::= FUNCTION(function_name {, function_arg}*)

```

my case is expected to work:

```plaintext
like_expression ::= FUNCTION(function_name {, function_arg}*) [NOT] LIKE pattern_value

```

My conclusion is that Hibernate does not comply with the spec.

I want to confirm I am right before filling a JIRA ticket.

Regards.

---

<div class="post-metadata">

**Author:** ![mbladel](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mbladel/32/2128_2.png) [@mbladel](https://discourse.hibernate.org/u/mbladel)\
**Post date:** [October 16, 2025, 2:19pm UTC](https://discourse.hibernate.org/t/jpql-function-call-not-working-in-like/11822/4 "2025-10-16T14:19:52Z")

</div>

Yes @ghislain-rouvignac_f, feel free to open a Jira and, while you’re at it, consider [contributing](http://hibernate.org/orm/contribute/) a fix yourself to the upstream Hibernate repository.

---

<div class="post-metadata">

**Author:** ![ghislain-rouvignac\_f](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/ghislain-rouvignac_f/32/4149_2.png) [@ghislain-rouvignac\_f](https://discourse.hibernate.org/u/ghislain-rouvignac_f)\
**Post date:** [October 17, 2025, 9:55am UTC](https://discourse.hibernate.org/t/jpql-function-call-not-working-in-like/11822/5 "2025-10-17T09:55:26Z")

</div>

Filled issue: [[HHH-19875] Hibernate not compliant with JPQL specification when calling “FUNCTION” in “LIKE” - Hibernate JIRA](https://hibernate.atlassian.net/browse/HHH-19875)
