Skip to content
New issue

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

fix: Bump Hibernate to 5.6.7.Final, use only named parameters in queries #140

Merged
merged 2 commits into from
Mar 24, 2022

Conversation

barbeau
Copy link
Member

@barbeau barbeau commented Mar 23, 2022

Summary:

This PR bumps the Hibernate version to 5.6.7.Final. However, errors are encountered:

javax.servlet.ServletException: java.lang.IllegalArgumentException: Could not locate ordinal parameter [0], expecting one of [1, 2, 3]
...

Full stack trace is detailed in #139.

EDIT - Problems seem to be solved by using named parameters only in queries - see #140 (comment).

Closes #139.

Expected behavior:

Everything should work as it previously did on the main branch - website should show validation results. However, the website currently appears blank.

Please make sure these boxes are checked before submitting your pull request - thanks!

  • Run the unit tests with mvn test to make sure you didn't break anything
  • Format the title like "feat: {new feature short description}" or "fix: {describe what was fixed}". Title must follow the Conventional Commit Specification (https://www.conventionalcommits.org/en/v1.0.0/).
  • Linked all relevant issues
  • Include screenshot(s) showing how this pull request works and fixes the issue(s)

Two issues, apparently starting with Hibernate 5.4:
1. Ordinal positional parameters (i.e., with numbers) must start at 1. Ours started at 0.
2. If we update the ordinal parameters to start at 1, we get another error "org.hibernate.engine.query.ParameterRecognitionException: Mixed parameter strategies - use just one of named, positional or JPA-ordinal strategy"

So, in this patch we update everything to use named parameters, which solves both issues.
@barbeau barbeau marked this pull request as ready for review March 23, 2022 21:27
@barbeau
Copy link
Member Author

barbeau commented Mar 23, 2022

There were two issues, apparently starting with Hibernate 5.4:

  1. Ordinal positional parameters (i.e., with numbers) must start at 1. Ours started at 0, and also just had a ? instead of a number too like ?1 in the query itself. See https://stackoverflow.com/questions/68619839/why-does-could-not-locate-ordinal-parameter-0-expecting-one-of-happen.
  2. If we update the ordinal parameters to start at 1 and the queries to add numbers after ?, we get another error "org.hibernate.engine.query.ParameterRecognitionException: Mixed parameter strategies - use just one of named, positional or JPA-ordinal strategy". See https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#jpql-api.

So, in this patch we update everything to use named parameters instead of a mix of ordinal and named parameters, which appears to solve both issues.

I tested on Windows 10 with JDK 17.0.2 and the webapp seems to work ok now, and the test all pass.

@barbeau barbeau changed the title chore: Bump Hibernate to 5.6.7.Final fix: Bump Hibernate to 5.6.7.Final, use only named queries Mar 23, 2022
@barbeau barbeau changed the title fix: Bump Hibernate to 5.6.7.Final, use only named queries fix: Bump Hibernate to 5.6.7.Final, use only named parameters in queries Mar 23, 2022
Copy link

@maximearmstrong maximearmstrong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thank you @barbeau !

@maximearmstrong maximearmstrong merged commit fd89ec9 into master Mar 24, 2022
@maximearmstrong maximearmstrong deleted the sean/bump-hibernate branch March 24, 2022 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ServletException - Could not locate ordinal parameter [0], expecting one of [1, 2, 3]
3 participants