No Persistence provider for EntityManager named

前端 未结 30 2403
甜味超标
甜味超标 2020-11-22 03:45

I have my persistence.xml with the same name using TopLink under the META-INF directory. Then, I have my code calling it with:

30条回答
  •  迷失自我
    2020-11-22 04:37

    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

提交回复
热议问题