我有一个DaoService,在应用程序启动时会被初始化。
public DaoService() {
Map<String, String> properties = new HashMap<String, String>();
properties.put("javax.persistence.jdbc.user", "admin");
properties.put("javax.persistence.jdbc.password", "admin");
factory = Persistence.createEntityManagerFactory("$objectdb/db/points.odb", properties);
//exception!
}
但每次它都会触发此异常:
javax.persistence.PersistenceException: Explicit persistence provider error(s) occurred for "$objectdb/db/points.odb" after trying the following discovered implementations: org.apache.openjpa.persistence.PersistenceProviderImpl, com.objectdb.jpa.Provider from provider: com.objectdb.jpa.Provider
at org.apache.myfaces.view.facelets.el.ContextAwareTagMethodExpression.invoke(ContextAwareTagMethodExpression.java:108)
at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:68)
at javax.faces.component.UICommand.broadcast(UICommand.java:120)
at javax.faces.component.UIViewRoot._broadcastAll(UIViewRoot.java:1028)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:286)
at javax.faces.component.UIViewRoot._process(UIViewRoot.java:1375)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:752)
at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:38)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:170)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:45)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: javax.el.ELException: javax.ejb.EJBException: The bean encountered a non-application exception; nested exception is:
javax.persistence.PersistenceException: Explicit persistence provider error(s) occurred for "$objectdb/db/points.odb" after trying the following discovered implementations: org.apache.openjpa.persistence.PersistenceProviderImpl, com.objectdb.jpa.Provider from provider: com.objectdb.jpa.Provider
at org.apache.el.parser.AstValue.invoke(AstValue.java:291)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
at org.apache.myfaces.view.facelets.el.ContextAwareTagMethodExpression.invoke(ContextAwareTagMethodExpression.java:96)
... 30 more
Caused by: javax.ejb.EJBException: The bean encountered a non-application exception; nested exception is:
javax.persistence.PersistenceException: Explicit persistence provider error(s) occurred for "$objectdb/db/points.odb" after trying the following discovered implementations: org.apache.openjpa.persistence.PersistenceProviderImpl, com.objectdb.jpa.Provider from provider: com.objectdb.jpa.Provider
at org.apache.openejb.core.ivm.BaseEjbProxyHandler.convertException(BaseEjbProxyHandler.java:363)
at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:283)
at $Proxy110.loginUser(Unknown Source)
at net.heatboxes.core.service.AuthorizationService.logIn(AuthorizationService.java:42)
at net.heatboxes.core.bean.view.Login.submit(Login.java:49)
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:601)
at org.apache.el.parser.AstValue.invoke(AstValue.java:278)
... 32 more
Caused by: javax.persistence.PersistenceException: Explicit persistence provider error(s) occurred for "$objectdb/db/points.odb" after trying the following discovered implementations: org.apache.openjpa.persistence.PersistenceProviderImpl, com.objectdb.jpa.Provider from provider: com.objectdb.jpa.Provider
at javax.persistence.Persistence.createPersistenceException(Persistence.java:244)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:186)
at net.heatboxes.dao.DaoService.<init>(DaoService.java:42)
at net.heatboxes.dao.DaoService.getInstance(DaoService.java:27)
at net.heatboxes.core.service.StatelessService.getDaoService(StatelessService.java:22)
at net.heatboxes.core.service.impl.AuthenticationServiceImpl.loginUser(AuthenticationServiceImpl.java:39)
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:601)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:181)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:163)
at net.heatboxes.core.interseptors.AccessControlInterceptor.interceptor(AccessControlInterceptor.java:32)
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:601)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:181)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:163)
at org.apache.openejb.cdi.CdiInterceptor.invoke(CdiInterceptor.java:126)
at org.apache.openejb.cdi.CdiInterceptor.access$000(CdiInterceptor.java:42)
at org.apache.openejb.cdi.CdiInterceptor$1.call(CdiInterceptor.java:63)
at org.apache.openejb.cdi.CdiInterceptor.aroundInvoke(CdiInterceptor.java:69)
at sun.reflect.GeneratedMethodAccessor54.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:181)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:163)
at org.apache.openejb.monitoring.StatsInterceptor.record(StatsInterceptor.java:176)
at org.apache.openejb.monitoring.StatsInterceptor.invoke(StatsInterceptor.java:95)
at sun.reflect.GeneratedMethodAccessor53.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:181)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:163)
at org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:138)
at org.apache.openejb.core.stateful.StatefulContainer.businessMethod(StatefulContainer.java:673)
at org.apache.openejb.core.stateful.StatefulContainer.invoke(StatefulContainer.java:378)
at org.apache.openejb.core.ivm.EjbObjectProxyHandler.synchronizedBusinessMethod(EjbObjectProxyHandler.java:246)
at org.apache.openejb.core.ivm.EjbObjectProxyHandler.businessMethod(EjbObjectProxyHandler.java:241)
at org.apache.openejb.core.ivm.EjbObjectProxyHandler._invoke(EjbObjectProxyHandler.java:83)
at org.apache.openejb.core.ivm.BaseEjbProxyHandler.invoke(BaseEjbProxyHandler.java:279)
... 40 more
Caused by: com.objectdb.o._PersistenceException: Failed to validate xml file C:\!heatboxes-web\build\web\WEB-INF\classes\META-INF\persistence.xml:
at com.objectdb.o._PersistenceException.b(_PersistenceException.java:45)
at com.objectdb.jpa.Provider.createEntityManagerFactory(Provider.java:87)
at com.objectdb.jpa.Provider.createEntityManagerFactory(Provider.java:32)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:152)
... 80 more
Caused by: com.objectdb.o.UserException: Failed to validate xml file C:\!heatboxes-web\build\web\WEB-INF\classes\META-INF\persistence.xml:
at com.objectdb.o.MSG.d(MSG.java:74)
at com.objectdb.o.XMD.n(XMD.java:217)
at com.objectdb.o.XMD.k(XMD.java:155)
at com.objectdb.o.UNM$z._e(UNM.java:182)
at com.objectdb.o.UNM$z.<init>(UNM.java:169)
at com.objectdb.o.UNM.x(UNM.java:105)
at com.objectdb.o.UNM.w(UNM.java:75)
at com.objectdb.jpa.Provider.createEntityManagerFactory(Provider.java:56)
... 82 more
Caused by: java.lang.NullPointerException
at javax.xml.validation.SchemaFactory.newSchema(SchemaFactory.java:623)
at com.objectdb.o.XMD.n(XMD.java:200)
... 88 more
我尝试使用和不使用此persistence.xml
<?xml version="1.0" encoding="UTF-8" ?>
<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_1_0.xsd" version="1.0">
<persistence-unit name="my-pu">
<description>My Persistence Unit</description>
<provider>com.objectdb.jpa.Provider</provider>
<class>net.heatboxes.dao.entity.UserEntity</class>
<properties>
<property name="javax.persistence.jdbc.url"
value="my.odb"/>
<property name="javax.persistence.jdbc.user" value="admin"/>
<property name="javax.persistence.jdbc.password" value="admin"/>
</properties>
</persistence-unit>
</persistence>
答案 0 :(得分:3)
最后我明白了。我根本不应该使用任何persistence.xml。当我不使用它时,我收到了这个错误:
HTTP状态500 - org.apache.openjpa.persistence.ArgumentException:JDBC驱动程序或 必须在ConnectionDriverName中指定DataSource类名 属性。配置中的可用属性是 “org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl@fdaf18ee”。
openjpa与我的objectdb.jar的现有JPA冲突。
为避免这种情况,我从TomEE openjpa-asm-shaded-
文件夹中删除了.jar
X.X.X /lib
。
<强>仅强>
Persistence.createEntityManagerFactory( “$ objectdb /分贝/ painInTheAss.odb”);
for EntityManagerFactory
<强>仅强>
objectdb-ee.jar
用于依赖项中的objectdb库。
仅限于:
OpenJPA的-ASM-阴影-X.X.X.jar
在TomEE /lib
Netbeans仍然可以为你创建persistance.xml,这将破坏一切。
如果您仍未成功并使用NetBeans,请在C:\Users\
YOURNAME \AppData\Local\NetBeans\Cache
您可以查看YOURPROJECT \nbproject\project.properties
,查看您玩过的旧格式错误的设置,并保持原样。