We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
array_includes
@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.
I'd expect that passing an array or a collection, should work.
I've to manually transform it into this form: array('val1', 'val2', ...), and pass it as a string and this is cumbersome.
array('val1', 'val2', ...)
No response
uname -a
ver
java -version
3.15.2 & Hibernate 6.6.x
mvnw --version
gradlew --version
The text was updated successfully, but these errors were encountered:
/cc @FroMage (panache), @loicmathieu (panache)
Sorry, something went wrong.
Thank you for reporting. Which database are you using? Function definitions in Hibernate ORM are dialect-specific, so it matters.
Ok, I had a look and actually the code is incorrect.
The stack trace tells you where the problem lies:
Caused by: org.hibernate.query.UnknownParameterException: No parameter labelled '?2' in query with ordinal parameters [1] ... 25 more
Hibernate is looking for a second parameter in the query, because you passed two parameters.
Why did you?
Well, this:
public static boolean accountNotExists_v1(String[] users) { return count("array_includes(accounts, ?1)", users) == 0; }
Should be this:
public static boolean accountNotExists_v1(String[] users) { return count("array_includes(accounts, ?1)", (Object) users) == 0; }
Otherwise users is passed to count as the array of parameters instead of the first parameter that happens to be an array.
users
count
It's basically Java typing, unrelated to Hibernate ORM or Panache.
Also, Intellij IDEA (at least, perhaps other IDEs as well) will warn you there's something dodgy in the code:
Closing since it's not a bug.
No branches or pull requests
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.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
orver
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
orgradlew --version
)No response
Additional information
No response
The text was updated successfully, but these errors were encountered: