I have my persistence.xml
with the same name using TopLink
under the META-INF
directory.
Then, I have my code calling it with:
You have to use the absolute path of the file otherwise this will not work. Then with that path we build the file and pass it to the configuration.
@Throws(HibernateException::class)
fun getSessionFactory() : SessionFactory {
return Configuration()
.configure(getFile())
.buildSessionFactory()
}
private fun getFile(canonicalName: String): File {
val absolutePathCurrentModule = System.getProperty("user.dir")
val pathFromProjectRoot = absolutePathCurrentModule.dropLastWhile { it != '/' }
val absolutePathFromProjectRoot = "${pathFromProjectRoot}module-name/src/main/resources/$canonicalName"
println("Absolute Path of secret-hibernate.cfg.xml: $absolutePathFromProjectRoot")
return File(absolutePathFromProjectRoot)
}
GL
Source