JPAcontainer这里的教程:https://vaadin.com/download/jpacontainer-tutorial/
表示您需要一个H2数据库驱动程序JPAcontainer.我不明白为什么?- 你有什么功能没有H2那么好JPAcontainer?
我正在使用vaadin为运行hibernate的应用程序开发UI 4.3.1我要做的是将数据绑定到vaadin JPAcontainer然后在Grid组件中使用它来允许延迟加载.但是当我尝试创建EntityManager时,它会抛出以下错误
java.lang.ClassCastException: org.hibernate.ejb.HibernatePersistence cannot be cast to javax.persistence.spi.PersistenceProvider
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
at com.vaadin.addon.jpacontainer.JPAContainerFactory.createEntityManagerForPersistenceUnit(JPAContainerFactory.java:122)
at com.vaadin.addon.jpacontainer.JPAContainerFactory.make(JPAContainerFactory.java:105)
Run Code Online (Sandbox Code Playgroud)
我使用了hibernate-jpa-2.1-api-1.0.0.Final.jar以及persistence-api-1.0.2.jar来导入我的EnityManager但是我一直得到同样的错误
这是我创建EntityManager的类
public class workManager{
public static void create() {
DataAccess dao= new DataAccess();
EntityManager em = Persistence //error here
.createEntityManagerFactory("myUI")
.createEntityManager();
em.getTransaction().begin();
dao.init();
List<work> list = dao.findAll(); //get all rows in table
em.persist(list);
dao.close();
em.getTransaction().commit();
}
Run Code Online (Sandbox Code Playgroud)
persistence.xml中
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="myProject">
<!-- Specify the JPA provider to use -->
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> …Run Code Online (Sandbox Code Playgroud)