- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 vaadin 为我运行 hibernate 4.3.1 的应用程序开发 UI我想要做的是将数据绑定(bind)到 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)
我使用了 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();
}
持久性.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>
在另一个类中我创建了 JPAContainer
private JPAContainer<work> container = JPAContainerFactory.make(work.class,
JpaProjectUI.PERSISTENCE_UNIT);
grid.setContainerDataSource(container);
这里是我的 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());
}
我正在关注 AddressBook demo JPAContainer 附加组件附带的
我正在使用 Tomcat 8 来运行我的应用程序
有人知道为什么会这样吗?如果问题不清楚,请随时向我询问更多信息!
这是我的 WEB-INF 文件夹中的 jar
我还在我的构建路径中添加了另一个项目,该项目具有以下 jar 列表
谢谢
最佳答案
请从您的 Web 应用程序中删除 persistence-api-1.0.2.jar
并查看结果。 hibernate-jpa 和 persistance-api 有冲突
关于hibernate.jpa.HibernatePersistenceProvider 无法转换为 javax.persistence.spi.PersistenceProvider,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31395133/
我正在创建一个 Spring MVC 和 Hibernate/JPA Web 应用程序,但在配置应用程序和 jboss 部署描述符时遇到问题,以便我可以将持久性管理委托(delegate)给我的 We
我正在使用 vaadin 为我运行 hibernate 4.3.1 的应用程序开发 UI我想要做的是将数据绑定(bind)到 vaadin JPAcontainer,然后在 Grid 组件中使用它以允
我这样搜索这个问题 How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version 但答案对我不起
我想这对于像我这样的初学者来说是一个很普遍的问题。但我找不到解决办法。然而。 文件persistence.xml在src/META-INF/persistence.xml
以前我使用org.hibernate.ejb.HibernatePersistence作为提供程序类,现在我将其更改为org.hibernate.jpa.HibernatePersistencePro
我对尝试将 JPA 2.1 PersistenceManager 与 Hibernate 5 一起使用的简单任务感到非常沮丧。 我打包了一个使用 weblogic ant 任务 jwsc (weblo
我是一名优秀的程序员,十分优秀!