im using vaadin to develop a UI for my application running hibernate 4.3.1 What I'm trying to do is bind the data to the vaadin JPAcontainer then use it in the Grid component to allow lazy-loading. But when I try and create the EntityManager it throws the following error
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)
I used the hibernate-jpa-2.1-api-1.0.0.Final.jar as well as the persistence-api-1.0.2.jar to import my EnityManager but I keep getting the same error
here is the class where I create the 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();
}
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>
in another class I create the JPAContainer
private JPAContainer<work> container = JPAContainerFactory.make(work.class,
JpaProjectUI.PERSISTENCE_UNIT);
grid.setContainerDataSource(container);
and here is where my EntityManager is called
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());
}
I was following the AddressBook demo that came with the JPAContainer add-on
I'm using Tomcat 8 to run my application
does anyone have an idea why this is happening? please feel free to ask me for more info if the problem isn't clear!
Here are the jars in my WEB-INF folder
I also added another project to my build path that has the following list of jars
thanks