Skip to content

array_includes doesn't accept a collection or array as input parameter #45468

Open
@Serkan80

Description

Describe the bug

I've the following Panache Entity, and I'm tring to use the array_includes function, however it doesn't accept an array as a parameter.

@Entity
class MyEntity extends PanacheEntity {

    @Array(length = 20)
    public String[] accounts;

  // doesn't work
  public static boolean accountNotExists_v1(String[] users) {
         return count("array_includes(accounts, ?1)", users) == 0;
    }

 // does work
  public static boolean accountNotExists_v2(String[] users) {
        var arrayParam = Arrays.stream(users)
                .map("'%s'"::formatted)
                .collect(joining(",", "array(", ")")); => will return 'array('user1', 'user2', ...)

        return count("array_includes(accounts, %s)".formatted(arrayParam)) == 0;
    }
}

I think the issue is with Hibernate and the documentation doesn't mention anything on the usage.

Expected behavior

I'd expect that passing an array or a collection, should work.

Actual behavior

I've to manually transform it into this form: array('val1', 'val2', ...), and pass it as a string and this is cumbersome.

How to Reproduce?

No response

Output of uname -a or ver

No response

Output of java -version

No response

Quarkus version or git rev

3.15.2 & Hibernate 6.6.x

Build tool (ie. output of mvnw --version or gradlew --version)

No response

Additional information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions