尝试持久化数据时显示以下错误:
[PersistenceException: [PersistenceUnit: update] class or package not found]
In C:UsersJohannDesktopSODETplay-2.1.1todolistappmodelsStream.java at line 32.
32 EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("update");
Stream.java (a model)
package models;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Id;
import javax.persistence.Persistence;
import com.restfb.Facebook;
@Entity
public class Stream {
@Facebook
@Id
public String post_id;
@Facebook
public String created_time;
@Facebook
public String message;
@Facebook
public String permalink;
@Override
public String toString() {
return String.format("%s, %s, %s, %s", created_time, message, permalink, post_id);
}
public void save(){
EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("update");
EntityManager entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
entityManager.persist(this);
entityManager.getTransaction().commit();
entityManager.close();
}
}
persistence.xml文件在conf/META-INF目录下:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="update" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>DefaultDS</non-jta-data-source>
<class>models.Stream</class>
<class>models.FacebookUser</class>
<class>models.Comment</class>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
</properties>
</persistence-unit>
</persistence>
这是 build。scala
import sbt._
import Keys._
import play.Project._
object ApplicationBuild extends Build {
val appName = "todolist"
val appVersion = "1.0-SNAPSHOT"
val appDependencies = Seq(
// Add your project dependencies here,
"com.restfb" % "restfb" % "1.6.11",
"mysql" % "mysql-connector-java" % "5.1.25",
"org.hibernate" % "hibernate-entitymanager" % "4.2.1.Final",
javaCore,
javaJdbc,
javaJpa
)
val main = play.Project(appName, appVersion, appDependencies).settings(
// Add your own project settings here
)
}
我看了文档,没有找到任何相关信息…
提前感谢!
注意你的application.conf中的名称与update: example:
不一样jpa.update = updatePersistenceUnit
我认为你没有这一行应用程序必须匹配在application.conf和hibernate文件
注意:hbm2dll中的值update仅用于在模型更改时更新DB模式。我认为你必须使用defaultPersistentUnit名称,因为在application.conf中它可能像这样:
jpa.default = defaultPersistenUnit
然后db.default.driver =你的驱动db.defalut.url =你的url
您的persistence.xml文件说明了以下配置:
<non-jta-data-source>DefaultDS</non-jta-data-source>
<persistence-unit name="update" transaction-type="RESOURCE_LOCAL">
您的application.conf必须包含以下条目
# You can expose this datasource via JNDI if needed (Useful for JPA)
db.default.jndiName=DefaultDS
# JPA configuration
# ~~~~~
# You can declare as many Ebean servers as you want.
# By convention, the default server is named `default`
jpa.default=update
查看您的映射或在这里找到一个清晰的解释