缺少maven web项目中的org.hibernate.ejb.hibernatePersistence类

时间:2014-03-20 16:32:51

标签: eclipse hibernate postgresql java-ee glassfish-4

我正在使用eclipse kepler,glassfish4.0,postgresSql 9.1构建名为“tuto.maven”的maven web项目(jsf + ejb3 + jpa2),但是我尝试在服务器上运行项目时出现问题 “无法部署tuto.maven 部署失败=部署期间发生错误:准备应用程序时出现异常:java.lang.ClassNotFoundException:org.hibernate.ejb.HibernatePersistence“

这是persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 
    xmlns="http://java.sun.com/xml/ns/persistence" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation= "http://java.sun.com/xml/ns/persistence 
         http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
    <persistence-unit name="persistence" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>jdbc/postgres</jta-data-source>
    <class>org.model.User</class>
    <properties>
      <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
      <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
      <property name="hibernate.show_sql" value="true" />
      </properties>

    </persistence-unit>
</persistence>

和pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.tuto</groupId>
  <artifactId>tuto.maven</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <repositories>
        <repository>
            <id>oss.sonatype.org</id>
            <name>OSS Sonatype Staging</name>
            <url>https://oss.sonatype.org/content/groups/staging</url>
        </repository>
        <repository>
            <id>java.net</id>
            <url>http://download.java.net/maven/2/</url>
        </repository>
    </repositories>
    <dependencies>
  <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
  </dependency>

    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.0-api</artifactId>
        <version>1.0.0.Final</version>
    </dependency>

    <dependency>
        <groupId>postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.1-901.jdbc4</version>
    </dependency>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-entitymanager</artifactId>
      <version>3.3.2.GA</version>
    </dependency>

<dependency>
    <groupId>javax.transaction</groupId>
    <artifactId>jta</artifactId>
    <version>1.0.1B</version>
</dependency>


  </dependencies>

</project>

请任何想法。

2 个答案:

答案 0 :(得分:1)

这是版本的问题,我使用的是最新版本并且可以使用。

答案 1 :(得分:0)

确保你有jar并在你的罐子里搜索prg.hibernate.ejb.HibernatePersistence类。

您还需要添加持久性单元。提及域类的名称。

<class>yourpackage.class</class>