我正在使用嵌入在 Tomcat 5.5.26 中的 OpenEJB 3.1.3,并使用 hibernate 3.6 作为 JPA 提供程序。
这是我的persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.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_1_0.xsd">
<persistence-unit name="manager1" transaction-type="JTA">
<!-- provider is optional if you work with only 1 JPA provider -->
<!--
<provider>org.hibernate.ejb.HibernatePersistence</provider>
-->
<jta-data-source>java:/DefaultDS</jta-data-source>
<!--
<properties>
<property name="hibernate.ejb.cfgfile" value="/hibernate.cfg.xml" />
</properties>
-->
</persistence-unit>
</persistence>
这是我的代码:
@Stateless
public class MapSearchManager implements MapSearchLocal, MapSearchRemote {
@PersistenceContext
private EntityManager em;
...
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public int queryDataSelectionNumRecords(MapSearchParamBean paramBean) {
Criteria c = createCriteria(paramBean);
c.setProjection(Projections.rowCount());
List l = c.list();
...
}
...
}
当我使用 OpenEJB 运行 tomcat 并在其中运行我的应用程序战争档案时,部署失败并出现异常堆栈跟踪:
2010-10-27 18:13:35,374 - ERROR - Unable to deploy collapsed ear in war /wma: Exception: Creating application failed: C:\apache-tomcat-5.5.26\webapps\wma: javax/persistence/spi/ProviderUtil
org.apache.openejb.OpenEJBException: Creating application failed: C:\apache-tomcat-5.5.26\webapps\wma: javax/persistence/spi/ProviderUtil
at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:666)
at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:449)
at org.apache.openejb.tomcat.catalina.TomcatWebAppBuilder.start(TomcatWebAppBuilder.java:249)
at org.apache.openejb.tomcat.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:58)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4148)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:926)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:889)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1149)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:736)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:448)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)
at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
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.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)
Caused by: java.lang.NoClassDefFoundError: javax/persistence/spi/ProviderUtil
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
at java.lang.Class.getConstructor0(Class.java:2699)
at java.lang.Class.newInstance0(Class.java:326)
at java.lang.Class.newInstance(Class.java:308)
at org.apache.openejb.assembler.classic.PersistenceBuilder.createEntityManagerFactory(PersistenceBuilder.java:179)
at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:489)
... 27 more
经过搜索,我发现该类javax/persistence/spi/ProviderUtil
是 Java EE 6/JPA 2.0 规范的一部分,OpenEJB 不支持该规范。但我不认为在我的应用程序中我使用任何 JPA 2.0。我在 1.0 的 persistence.xml 中特别提到。我知道休眠 3.6 支持 JPA 2.0。我不知道 hibernate 的 Criteria API 是否是 JPA 2.0 的一部分,但这不应该导致问题,因为我在 persistence.xml 中特别提到了 1.0。
谢谢您的帮助。
问候
将要