2013-01-19 49 views
1

我努力學習JPA-休眠與本網站提到 https://schuchert.wikispaces.com/JPA+Tutorial+1+-+Getting+Started (我曾嘗試備用鏈路以及一個非常簡單的例子,但都結束了在我描述我這裏簡要例如我所列舉的項目的重要者除外JPA -HIBERNATE tuorial:顯式持久性提供程序錯誤,無法創建配置

Explicit persistence provider error(s) occurred for "examplePersistenceUnit" after trying the following discovered implementations: org.hibernate.ejb.HibernatePersistence from provider: org.hibernate.ejb.HibernatePersistence 
Caused by: org.hibernate.HibernateException: Unable to build the default ValidatorFactory 
Caused by: javax.validation.ValidationException: Could not create Configuration. 
    at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:175) 
Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 

配置相同的問題)

如下 的persistence.xml {src文件夾目錄META-INF內}

<persistence 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" 
      version="2.0"> 
    <persistence-unit name="examplePersistenceUnit" 
         transaction-type="RESOURCE_LOCAL">  
     <properties> 
      <property name="hibernate.show_sql" value="false" /> 
      <property name="hibernate.format_sql" value="false" /> 

      <property name="hibernate.connection.driver_class" 
         value="org.hsqldb.jdbcDriver" /> 
      <property name="hibernate.connection.url" 
         value="jdbc:hsqldb:mem:mem:aname" /> 
      <property name="hibernate.connection.username" value="sa" /> 

      <property name="hibernate.dialect" 
         value="org.hibernate.dialect.HSQLDialect" /> 
      <property name="hibernate.hbm2ddl.auto" value="create" /> 
     </properties> 
    </persistence-unit> 
</persistence> 

,然後我有一個簡單的JUnit類執行以下操作

@Before 
    public void init(){ 
     BasicConfigurator.configure(); 
      Logger.getLogger("org").setLevel(Level.TRACE); 
     emf= Persistence.createEntityManagerFactory("examplePersistenceUnit"); 
     em = emf.createEntityManager(); 

    } 

任何一個可以幫我解決這個我想在論壇上搜索,並用反編譯調試,但也是沒有使用

全部異常跟蹤

javax.persistence.PersistenceException: Explicit persistence provider error(s) occurred for "examplePersistenceUnit" after trying the following discovered implementations: org.hibernate.ejb.HibernatePersistence from provider: org.hibernate.ejb.HibernatePersistence 
    at javax.persistence.Persistence.createPersistenceException(Persistence.java:244) 
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:186) 
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:72) 
    at entity.PersonTest.init(PersonTest.java:22) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:616) 
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) 
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) 
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24) 
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) 
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) 
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) 
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) 
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) 
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) 
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) 
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) 
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309) 
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) 
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) 
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) 
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: examplePersistenceUnit] Unable to build EntityManagerFactory 
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915) 
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890) 
    at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:57) 
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:152) 
    ... 26 more 
Caused by: org.hibernate.HibernateException: Error applying BeanValidation relational constraints 
    at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.applyRelationalConstraints(BeanValidationIntegrator.java:219) 
    at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.integrate(BeanValidationIntegrator.java:126) 
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:303) 
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1750) 
    at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:94) 
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:905) 
    ... 29 more 
Caused by: java.lang.reflect.InvocationTargetException 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:616) 
    at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.applyRelationalConstraints(BeanValidationIntegrator.java:208) 
    ... 34 more 
Caused by: org.hibernate.HibernateException: Unable to build the default ValidatorFactory 
    at org.hibernate.cfg.beanvalidation.TypeSafeActivator.getValidatorFactory(TypeSafeActivator.java:524) 
    at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyDDL(TypeSafeActivator.java:119) 
    ... 39 more 
Caused by: javax.validation.ValidationException: Could not create Configuration. 
    at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:175) 
    at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:50) 
    at org.hibernate.cfg.beanvalidation.TypeSafeActivator.getValidatorFactory(TypeSafeActivator.java:521) 
    ... 40 more 
Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 
    at java.util.ArrayList.rangeCheck(ArrayList.java:571) 
    at java.util.ArrayList.get(ArrayList.java:349) 
    at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:173) 
    ... 42 more 

回答

2

是在類路徑中的Hibernate驗證?

如果您使用的是Maven,只需爲相應的Hibernate版本()添加dependency即可。

+0

非常感謝!它的工作,我仍然想知道如何調試這些類型的問題。你是如何得出這個結論的? – Geek

+0

從JPA開始時,忽視這一點很常見。我們都在那裏:) –

相關問題