我在尝试使用EntityManagerFactory而不是SessionFactory时遇到了问题。该模型基于注释,并使用SessionFactory进行测试。
这是堆栈跟踪
java.lang.ExceptionInInitializerError at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:422) at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:195) at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:244) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:241) 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: ethiopianMarketdb] Unable to configure EntityManagerFactory at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:378) at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63) at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47) at org.dejach.marketApi.AdministratorApiTest.(AdministratorApiTest.java:12) ... 22 more Caused by: org.hibernate.HibernateException: Unable to get the default Bean Validation factory at org.hibernate.cfg.beanvalidation.BeanValidationActivator.applyDDL(BeanValidationActivator.java:127) at org.hibernate.cfg.Configuration.applyBeanValidationConstraintsOnDDL(Configuration.java:1704) at org.hibernate.cfg.Configuration.applyConstraintsToDDL(Configuration.java:1654) at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1445) at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1375) at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1519) at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:193) at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1100) at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:282) at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:366) ... 26 more Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.hibernate.cfg.beanvalidation.BeanValidationActivator.applyDDL(BeanValidationActivator.java:118) ... 35 more Caused by: java.lang.NoClassDefFoundError: javax/validation/ParameterNameProvider at org.hibernate.validator.HibernateValidator.createGenericConfiguration(HibernateValidator.java:31) at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:269) at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:111) at org.hibernate.cfg.beanvalidation.TypeSafeActivator.getValidatorFactory(TypeSafeActivator.java:380) at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyDDL(TypeSafeActivator.java:109) ... 40 more Caused by: java.lang.ClassNotFoundException: javax.validation.ParameterNameProvider at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 45 more
package org.dejach.marketApi; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; import org.dejach.Address; import org.dejach.Role; import org.junit.Test; public class AdministratorApiTest { static EntityManagerFactory emf = Persistence.createEntityManagerFactory( "ethiopianMarketdb" ); static EntityManager em= emf.createEntityManager(); MarketApi marketApi = new MarketApi(); @Test public void testView() { } @Test public void testAdd() throws MarketApiExceptions { MarketApi.setEm(em); Address address = new Address(); address.setCityName("Addis Ababa"); address.setCountryName("Ethiopia"); address.setEmail("dgdoorvan@yahoo.com"); address.setFixedLinePhoneNo("None"); address.setHouseNo("905"); address.setMobilePhoneNo("+251912978393"); address.setStreetName("Kotebe"); AdministratorApi administratorApi = new AdministratorApi(); administratorApi.setAdministratorAddress(address); administratorApi.setAdministratorId("Admin ID"); administratorApi.setPassword("DGrekik377"); administratorApi.setRole(Role.dejach.name()); administratorApi.setFirstName("Dejazmach"); administratorApi.setLastName("Getachew"); administratorApi.setUserName("User Dejach"); administratorApi.setStatus(true); this.marketApi.addAdministrator(administratorApi); } @Test public void testDelete() { } @Test public void testUpdate() { } }