79278011

Date: 2024-12-13 10:48:17
Score: 2
Natty:
Report link

I think I have found the issue. The problem was with my configuration and the Hibernate starter guide. This might save some other people some time.

The starter guide has references to URL, USER variables when setting the config, which from the imports, suggests these are available from:

org.hibernate.cfg.AvailableSettings.*

Which might be true for Java. However, they are actually located in an inherited class:

org.hibernate.cfg.JdbcSettings

So in Scala:

import org.hibernate.cfg.JdbcSettings._

This then allowed me to set my config like this:

val config = new Configuration()
  .addAnnotatedClass(classOf[Registration])
  .setProperty(JAKARTA_JDBC_URL, getConnectionString)
  .setProperty(JAKARTA_JDBC_USER, user)
  .setProperty(JAKARTA_JDBC_PASSWORD, pw)
  // 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")

Another note, the documentation is actually out of date. URL, USER and PASS are deprecated, you must use JAKARTA_JDBC_* (see above config) to set the values.

This fixed the above issue, so I'm marking this as resolved. I am not getting issues connecting to the database, which is outside the scope of the original question. I hope (given I found several people online having the same problems), this saves someone some time.

Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • Me too answer (2.5): having the same problem
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Kris Rice