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

MySQL fails when 'cachePrepStmts' is 'true' #549

Open
philwebb opened this issue Oct 16, 2024 · 3 comments · May be fixed by #559
Open

MySQL fails when 'cachePrepStmts' is 'true' #549

philwebb opened this issue Oct 16, 2024 · 3 comments · May be fixed by #559
Labels
bug Something isn't working

Comments

@philwebb
Copy link

Describe the bug
This issue is described in https://stackoverflow.com/questions/79092147/springboot-3-3-4-app-hikari-mysql-and-gradlew-nativecompile.

The exception raised is:

Exception in thread "main" com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: Can not find class 'com.mysql.cj.PerConnectionLRUFactory' specified by the 'queryInfoCacheFactory' configuration property.
	at com.zaxxer.hikari.pool.HikariPool.throwPoolInitializationException(HikariPool.java:584)
	at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:571)
	at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:98)
	at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:80)
	at com.jesusbianco.Utilities.getMySQLDataSourceConnectionPool(Utilities.java:40)
	at com.jesusbianco.Application.main(Application.java:30)
Caused by: java.sql.SQLException: Can not find class 'com.mysql.cj.PerConnectionLRUFactory' specified by the 'queryInfoCacheFactory' configuration property.
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:67)
	at com.mysql.cj.jdbc.ConnectionImpl.createPreparedStatementCaches(ConnectionImpl.java:1033)
	at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:420)
	at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:241)
	at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
	at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:137)
	at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:360)
	at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:202)
	at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:461)
	at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:550)
	... 4 more
Caused by: java.lang.ClassNotFoundException: com.mysql.cj.PerConnectionLRUFactory
	at org.graalvm.nativeimage.builder/com.oracle.svm.core.hub.ClassForNameSupport.forName(ClassForNameSupport.java:123)
	at org.graalvm.nativeimage.builder/com.oracle.svm.core.hub.ClassForNameSupport.forName(ClassForNameSupport.java:87)
	at java.base@20.0.1/java.lang.Class.forName(DynamicHub.java:1324)
	at java.base@20.0.1/java.lang.Class.forName(DynamicHub.java:1287)
	at java.base@20.0.1/java.lang.Class.forName(DynamicHub.java:1280)
	at com.mysql.cj.jdbc.ConnectionImpl.createPreparedStatementCaches(ConnectionImpl.java:1025)

To Reproduce

Run the sample attached to the stackoverflow.com question or any MySQL example where the cachePrepStmts data source property is set to true.

Expected behavior
The metadata should provide reflection hints for com.mysql.cj.PerConnectionLRUFactory.

Logs
See stackoverflow.com quesstion

System Info (please complete the following information):

  • OS: MacOS
  • GraalVM Version [e.g. Liberica-NIK-23.0.0-1]
  • Java Version [e.g. 20]
  • Plugin version [e.g. native-gradle-plugin:0.10.3]

Additional context
Add any other context about the problem here.

@philwebb philwebb added the bug Something isn't working label Oct 16, 2024
@philwebb
Copy link
Author

In the meantime adding a src/main/resources/META-INF/native-image/com.mysql/mysql-connector-j/reflect-config.json file with the following will work around the issue:

[
  {
    "name" : "com.mysql.cj.PerConnectionLRUFactory",
    "allPublicConstructors" : true
  }
]

@vjovanov
Copy link
Member

vjovanov commented Nov 4, 2024

@philwebb thanks for reporting! Could you open a PR with these changes so we can merge them? Ideally, we would also have a test that covers the code path that is failing.

@philwebb
Copy link
Author

philwebb commented Nov 4, 2024

@vjovanov, The issue was actually originally raised by @jbiancot. I just did some analysis. Perhaps they might be able to raise a PR.

wilkinsona added a commit to wilkinsona/graalvm-reachability-metadata that referenced this issue Nov 4, 2024
wilkinsona added a commit to wilkinsona/graalvm-reachability-metadata that referenced this issue Nov 4, 2024
@wilkinsona wilkinsona linked a pull request Nov 4, 2024 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants