我正在尝试使用 JPA 使用 Play 2 保存数据,但我得到:
Execution exception
[IllegalArgumentException: Unknown entity: models.Stream];
流 .java`
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("defaultPersistenceUnit");
EntityManager entityManager = entityManagerFactory.createEntityManager();
entityManager.getTransaction().begin();
entityManager.persist(this);
entityManager.getTransaction().commit();
entityManager.close();
}
}
`
持久性.xml
`
<persistence-unit name="defaultPersistenceUnit">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/fiatbr_db"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value="1234"/>
<property name="hibernate.archive.autodetection" value="class"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hbm2ddl.auto" value="create"/>
</properties>
</persistence-unit>
`
有什么遗漏吗?任何配置错误?看起来模型 Stream 没有找到,但是怎么找不到呢?还有更多要在类中添加注释@Entity 的东西吗?谢谢 :)