0
我試圖獲取配置Hibernate與我的Scala代碼的工作,當我去運行應用程序,我得到如下:沒有持久性提供的EntityManager
javax.persistence.PersistenceException: No Persistence provider for EntityManager named studentalerts
javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
hibernateconfig.HibernateConfig$.getEntityManager(HibernateConfig.scala:29)
hibernateconfig.HibernateConfig$.createEntityManager(HibernateConfig.scala:11)
controller.test.<init>(test.scala:8)
controller.TestHome.doGet(register.scala:11
我的persistence.xml文件(在我的WEB -INF /班/ META-INF文件夾如下
<persistence-unit name="studentalerts" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<non-jta-data-source>jdbc/studentalerts</non-jta-data-source>
<properties>
</properties>
</persistence-unit>
和我的相關Scala代碼是
object HibernateConfig {
var mapping: SearchMapping = _
def createEntityManager(): EntityManager = getEntityManager
def getEntityManager: EntityManager = {
val properties: Properties = new Properties()
properties.put("javax.persistence.provider", "org.hibernate.jpa.HibernatePersistenceProvider")
properties.put("javax.persistence.transactionType", "RESOURCE_LOCAL")
properties.put("javax.persistence.jdbc.url", "jdbc:mysql://localhost:3306/studentalerts")
properties.put("javax.persistence.jdbc.user", "alert")
properties.put("javax.persistence.jdbc.password", "12345")
properties.put("javax.persistence.jdbc.driver", "com.mysql.jdbc.Driver")
properties.put("hibernate.hbm2ddl.auto", "update")
properties.put("hibernate.show_sql", "false")
properties.put("hibernate.format_sql", "false")
properties.put("hibernate.current_session_context_class", "thread")
properties.put("hibernate.transaction.factory_class", "org.hibernate.transaction.JDBCTransactionFactory")
properties.put("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect")
val emf: EntityManagerFactory = Persistence.createEntityManagerFactory("studentalerts", properties)
emf.createEntityManager()
}
}
它具有硬時間線與
val emf: EntityManagerFactory = Persistence.createEntityManagerFactory("studentalerts", properties)
任何幫助不勝感激。
感謝