2013-10-09 144 views
0

我有這個項目,我使用hibernate,gwt,JPA,Tomcat和spring。無論如何,我一直試圖解決這個錯誤沒有成功。這是我的錯誤:無法配置EntityManagerFactory(沒有持久性)

  log4j:WARN No appenders could be found for logger(org.hibernate.cfg.annotations.Version). 
     Please initialize the log4j system properly. 
     Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit:   projetA] Unable to configure EntityManagerFactory 
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:371) 
    atorg.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:55) 
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48) 
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32) 
    at com.pac.projetA.shared.Dto.Main.main(Main.java:14) 
     Caused by: org.hibernate.HibernateException: Unable to get the default Bean  Validation factory 
    at org.hibernate.cfg.beanvalidation.BeanValidationActivator.applyDDL(BeanValidationActivator.java:104) 
    at org.hibernate.cfg.AnnotationConfiguration.applyBeanValidationConstraintsOnDDL(AnnotationConfiguration.java:477) 
    at org.hibernate.cfg.AnnotationConfiguration.applyConstraintsToDDL(AnnotationConfiguration.java:429) 
    at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:403) 
    at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1206) 
    at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1449) 
    at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:193) 
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1077) 
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:275) 
    at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:359) 
    ... 4 more 
Caused by: java.lang.reflect.InvocationTargetException 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)`enter code here` 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.hibernate.cfg.beanvalidation.BeanValidationActivator.applyDDL(BeanValidationActivator.java:95) 
    ... 13 more 

回答

0

您需要將hibernate-validator添加到您的項目中。

http://www.hibernate.org/subprojects/validator/download

如果你想擺脫log4j的警告,你應該增加一個log4j.properties文件。

刪除它,這是不需要的,幾乎肯定會導致錯誤。如果你看到我以前的評論,我建議刪除這個。這只是界面綁定,而不是jsr303驗證API的實現代碼。 Hibernate首先看到了這一點,並沒有使用hibernate-validator庫進行驗證。

<dependency> 
     <groupId>javax.validation</groupId> 
     <artifactId>validation-api</artifactId> 
     <version>1.0.0.GA</version> 
     <scope>test</scope> 
    </dependency> 
+0

它仍是同樣的錯誤:( – mitchi

+0

OK,這可能是從GWT驗證的API classpath中。如果你有hibernate-你可以將其刪除驗證器在你的類路徑中使用maven –

+0

我使用maven – mitchi

0

的pom.xml

<?xml version="1.0" encoding="UTF-8"?> 
<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/maven-v4_0_0.xsd"> 

    <!-- POM file generated with GWT webAppCreator --> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.pac</groupId> 
    <artifactId>projetA</artifactId> 
    <packaging>war</packaging> 
    <version>0.0.1-SNAPSHOT</version> 
    <name>GWT Maven Archetype</name> 

    <properties> 
     <!-- Convenience property to set the GWT version --> 
     <gwtVersion>2.5.1</gwtVersion> 
     <springframeworkVersion>3.2.3.RELEASE</springframeworkVersion> 
     <org.hibernate.version>3.5.1-Final</org.hibernate.version> 
     <!-- <tomcat.webport>8082</tomcat.webport> <tomcat.ajpport>8182</tomcat.ajpport> 
      <tomcat.context>/parent</tomcat.context> --> 
     <!-- GWT needs at least java 1.5 --> 
     <webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
    </properties> 

    <dependencies> 
     <dependency> 
      <groupId>com.google.gwt</groupId> 
      <artifactId>gwt-servlet</artifactId> 
      <version>${gwtVersion}</version> 
      <scope>runtime</scope> 
     </dependency> 
     <dependency> 
      <groupId>com.google.gwt</groupId> 
      <artifactId>gwt-user</artifactId> 
      <version>${gwtVersion}</version> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>4.7</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
      <groupId>javax.validation</groupId> 
      <artifactId>validation-api</artifactId> 
      <version>1.0.0.GA</version> 
      <scope>test</scope> 
     </dependency> 
     <dependency> 
    <groupId>org.hibernate</groupId> 
    <artifactId>hibernate-validator</artifactId> 
    <version>5.0.1.Final</version> 
</dependency> 
     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-core</artifactId> 
      <version>${org.hibernate.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-annotations</artifactId> 
      <version>${org.hibernate.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.hibernate</groupId> 
      <artifactId>hibernate-entitymanager</artifactId> 
      <version>${org.hibernate.version}</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>org.slf4j</groupId> 
      <artifactId>slf4j-log4j12</artifactId> 
      <version>1.5.8</version> 
     </dependency> 

     <!-- Apache log4j --> 
     <dependency> 
      <groupId>log4j</groupId> 
      <artifactId>log4j</artifactId> 
      <version>1.2.17</version> 
     </dependency> 

     <dependency> 
      <groupId>c3p0</groupId> 
      <artifactId>c3p0</artifactId> 
      <version>0.9.1.2</version> 
     </dependency> 

     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-core</artifactId> 
      <version>${springframeworkVersion}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-beans</artifactId> 
      <version>${springframeworkVersion}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-context</artifactId> 
      <version>${springframeworkVersion}</version> 
     </dependency> 





    </dependencies> 

    <build> 
     <!-- Generate compiled stuff in the folder used for developing mode --> 
     <outputDirectory>${webappDirectory}/WEB-INF/classes</outputDirectory> 

     <plugins> 

      <!-- GWT Maven Plugin --> 
      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>gwt-maven-plugin</artifactId> 
       <version>2.5.1</version> 
       <executions> 
        <execution> 
         <goals> 
          <goal>compile</goal> 
          <goal>test</goal> 
          <goal>generateAsync</goal> 
         </goals> 
        </execution> 
       </executions> 
       <!-- Plugin configuration. There are many available options, see gwt-maven-plugin 
        documentation at codehaus.org --> 
       <configuration> 
        <runTarget>projetA.html</runTarget> 
        <hostedWebapp>${webappDirectory}</hostedWebapp> 
        <i18nMessagesBundle>com.pac.projetA.client.Messages</i18nMessagesBundle> 
       </configuration> 
      </plugin> 

      <!-- Copy static web files before executing gwt:run --> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-war-plugin</artifactId> 
       <version>2.1.1</version> 
       <executions> 
        <execution> 
         <phase>compile</phase> 
         <goals> 
          <goal>exploded</goal> 
         </goals> 
        </execution> 
       </executions> 
       <configuration> 
        <webappDirectory>${webappDirectory}</webappDirectory> 
       </configuration> 
      </plugin> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>2.3.2</version> 
       <configuration> 
        <source>1.5</source> 
        <target>1.5</target> 
       </configuration> 
      </plugin> 
      <!-- <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> 
       <version>2.0</version> <configuration> <path>${tomcat.context}</path> <port>${tomcat.webport}</port> 
       <ajpPort>${tomcat.ajpport}</ajpPort> <systemProperties> <JAVA_OPTS>-XX:MaxPermSize=256m</JAVA_OPTS> 
       </systemProperties> </configuration> </plugin> --> 

     </plugins> 
    </build> 

</project> 
+0

你應該添加pom到你的問題,而不是在這裏發帖作爲答案:D –

相關問題