Когда я пытаюсь запустить базу данных, я получаю следующее исключение:
Код: Выделить всё
[error] java.lang.ExceptionInInitializerError
[error] at ServerRoutes.$init$$$anonfun$1$$anonfun$1$$anonfun$1$$anonfun$1(ServerRoutes.scala:34)
[error] at akka.http.scaladsl.server.util.ApplyConverterInstances.akka$http$scaladsl$server$util$ApplyConverterInstances$$anon$1$$_$apply$$anonfun$1(ApplyConverterInstances.scala:14)
[error] at akka.http.scaladsl.server.ConjunctionMagnet$$anon$3.apply$$anonfun$1$$anonfun$1$$anonfun$1(Directive.scala:234)
...
[error] Caused by: org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] due to: java.lang.RuntimeException: Unable to get java.sql.Driver from DriverManager
...
[error] Caused by: java.lang.RuntimeException: Unable to get java.sql.Driver from DriverManager
[error] at io.agroal.pool.ConnectionFactory.newDriver(ConnectionFactory.java:130)
[error] at io.agroal.pool.ConnectionFactory.(ConnectionFactory.java:68)
[error] at io.agroal.pool.ConnectionPool.(ConnectionPool.java:112)
[error] at io.agroal.pool.DataSource.(DataSource.java:37)
[error] at io.agroal.pool.DataSourceProvider.getDataSource(DataSourceProvider.java:21)
[error] at io.agroal.api.AgroalDataSource.from(AgroalDataSource.java:41)
[info] at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:136)
[info] at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:247)
[info] at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:215)
[info] at org.hibernate.service.ServiceRegistry.requireService(ServiceRegistry.java:68)
[info] at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.java:434)
[error] at io.agroal.api.AgroalDataSource.from(AgroalDataSource.java:33)
[error] at org.hibernate.agroal.internal.AgroalConnectionProvider.configure(AgroalConnectionProvider.java:93)
[error] ... 78 more
[error] Caused by: java.sql.SQLException: No suitable driver
[error] at java.sql/java.sql.DriverManager.getDriver(DriverManager.java:300)
[error] at io.agroal.pool.ConnectionFactory.newDriver(ConnectionFactory.java:128)
[error] ... 85 more
[info] at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.getJdbcEnvironmentUsingJdbcMetadata(JdbcEnvironmentInitiator.java:305)
[info] at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:129)
[info] at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:81)
[info] at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:130)
[info] at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263)
Зависимости build.sbt:
Код: Выделить всё
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-http" % akkaHttpVersion,
"com.typesafe.akka" %% "akka-http-spray-json" % akkaHttpVersion,
"com.typesafe.akka" %% "akka-actor-typed" % akkaVersion,
"com.typesafe.akka" %% "akka-stream" % akkaVersion,
"ch.qos.logback" % "logback-classic" % "1.5.12",
"com.thesamet.scalapb" %% "scalapb-runtime" % scalapb.compiler.Version.scalapbVersion % "protobuf",
"com.thesamet.scalapb" %% "scalapb-json4s" % "0.12.1",
"commons-codec" % "commons-codec" % "1.17.1",
"com.typesafe.akka" %% "akka-http-testkit" % akkaHttpVersion % Test,
"com.typesafe.akka" %% "akka-actor-testkit-typed" % akkaVersion % Test,
"org.scalatest" %% "scalatest" % "3.2.19" % Test,
"org.hibernate.orm" % "hibernate-core" % "6.6.3.Final",
"org.hibernate.validator" % "hibernate-validator" % "8.0.0.Final",
"org.glassfish" % "jakarta.el" % "5.0.0-M1" % Test,
"io.agroal" % "agroal-pool" % "2.5",
"org.hibernate.orm" % "hibernate-agroal" % "6.4.4.Final",
"com.mysql" % "mysql-connector-j" % "9.1.0",
"com.lihaoyi" %% "upickle" % "4.0.2"
)
Код: Выделить всё
def init() : Unit = {
sessionFactory = new Configuration()
.addAnnotatedClass(classOf[Registration])
.setProperty("driver", "com.mysql.cj.jdbc.Driver")
.setProperty("url", "jdbc:mysql://localhost:3306/hydra_data")
.setProperty("user", "root")
.setProperty("password", "")
// use Agroal connection pool
.setProperty("hibernate.agroal.maxSize", "20")
// display SQL in console
.setProperty("show_sql", "true")
.setProperty("format_sql", "true")
.setProperty("highlight_sql", "true")
.buildSessionFactory()
sessionFactory.getSchemaManager.exportMappedObjects(true)
...
}
Версия Java:
Код: Выделить всё
OpenJDK 64-Bit Server VM (build 23.0.1+11-39, mixed mode, sharing)Версия Sbt: 1.10.6
ОБНОВЛЕНИЕ:Как предложил @GaëlJ, я попробовал следующее:
Код: Выделить всё
val sqlDriver = classOf[com.mysql.cj.jdbc.Driver]и попытался добавить его в функцию инициализации моей базы данных
Код: Выделить всё
classOf[com.mysql.cj.jdbc.Driver].getDeclaredConstructor().newInstance()
ОБНОВЛЕНИЕ 2:
Я перешел по некоторым ссылкам на внутренние файлы Hibernate в выводе ошибки. Я обнаружил, что класс ConnectionFactory вызывает DriverManager.getDriver и передает URL-адрес, определенный в конфигурации, в функцию, чтобы определить, какой драйвер использовать.
Так я и сделал. это вручную, и я получаю правильный ответ. Так почему же это внутренний сбой? Возможно, это ошибка?

Подробнее здесь: https://stackoverflow.com/questions/792 ... sql-driver
Мобильная версия