Red*_*eda 0 tomcat hibernate vaadin 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>
<!-- Entity beans go here -->
<class>com.dao.model.Work</class>
<properties>
<!-- DB connection properties -->
<property name="javax.persistence.jdbc.url" value="jdbc:sqlserver://S12345:1111;databaseName=dbName" />
<!-- property name="javax.persistence.jdbc.url" value="jdbc:sqlserver://L71111:1111;databaseName=dbName" / -->
<property name="javax.persistence.jdbc.user" value="iaSys" />
<property name="javax.persistence.jdbc.password" value="password" />
<property name="javax.persistence.jdbc.driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<!-- Settings for c3p0 connection pooling -->
<property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider" />
<property name="hibernate.c3p0.max_size" value="100" />
<property name="hibernate.c3p0.min_size" value="0" />
<property name="hibernate.c3p0.acquire_increment" value="1" />
<property name="hibernate.c3p0.idle_test_period" value="300" />
<property name="hibernate.c3p0.max_statements" value="0" />
<property name="hibernate.c3p0.timeout" value="100" />
</properties>
</persistence-unit>
Run Code Online (Sandbox Code Playgroud)
在另一个类中,我创建了JPAContainer
private JPAContainer<work> container = JPAContainerFactory.make(work.class,
JpaProjectUI.PERSISTENCE_UNIT);
grid.setContainerDataSource(container);
Run Code Online (Sandbox Code Playgroud)
这是调用我的EntityManager的地方
public class JpaPojectUI extends UI {
private static final long serialVersionUID = 1L;
public static final String PERSISTENCE_UNIT = "myProject";
static {
workManager.create();
}
@Override
protected void init(VaadinRequest request) {
setContent(new mainUI());
}
Run Code Online (Sandbox Code Playgroud)
我正在关注JPAContainer插件附带的AddressBook演示
我正在使用Tomcat 8来运行我的应用程序
有没有人知道为什么会这样?如果问题不明确,请随时向我询问更多信息!
这是我的WEB-INF文件夹中的jar

我还在我的构建路径中添加了另一个项目,该项目具有以下jar列表

谢谢
| 归档时间: |
|
| 查看次数: |
4631 次 |
| 最近记录: |