我正在尝试使用Java EE创建一个简单的项目。但是,我得到了一个巨大的堆栈跟踪。
org.apache.openejb.config.ValidationFailedException: Module failed validation. AppModule(name=BarSystem_war_exploded)
at org.apache.openejb.config.ReportValidationResults.deploy(ReportValidationResults.java:88)
at org.apache.openejb.config.AppInfoBuilder.build(AppInfoBuilder.java:312)
at org.apache.openejb.config.ConfigurationFactory.configureApplication(ConfigurationFactory.java:974)
at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1227)
at org.apache.tomee.catalina.TomcatWebAppBuilder.configureStart(TomcatWebAppBuilder.java:1100)
at org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:130)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5416)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
at org.apache.tomee.catalina.TomcatWebAppBuilder.deployWar(TomcatWebAppBuilder.java:663)
at org.apache.tomee.catalina.TomcatWebAppBuilder.deployWebApps(TomcatWebAppBuilder.java:622)
at org.apache.tomee.catalina.deployment.TomcatWebappDeployer.deploy(TomcatWebappDeployer.java:43)
at org.apache.openejb.assembler.DeployerEjb.deploy(DeployerEjb.java:176)
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.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:192)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:173)
at org.apache.openejb.security.internal.InternalSecurityInterceptor.invoke(InternalSecurityInterceptor.java:35)
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.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:192)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:173)
at org.apache.openejb.monitoring.StatsInterceptor.record(StatsInterceptor.java:181)
at org.apache.openejb.monitoring.StatsInterceptor.invoke(StatsInterceptor.java:100)
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.apache.openejb.core.interceptor.ReflectionInvocationContext$Invocation.invoke(ReflectionInvocationContext.java:192)
at org.apache.openejb.core.interceptor.ReflectionInvocationContext.proceed(ReflectionInvocationContext.java:173)
at org.apache.openejb.core.interceptor.InterceptorStack.invoke(InterceptorStack.java:85)
at org.apache.openejb.core.stateless.StatelessContainer._invoke(StatelessContainer.java:227)
at org.apache.openejb.core.stateless.StatelessContainer.invoke(StatelessContainer.java:194)
at org.apache.openejb.server.ejbd.EjbRequestHandler.doEjbObject_BUSINESS_METHOD(EjbRequestHandler.java:370)
at org.apache.openejb.server.ejbd.EjbRequestHandler.processRequest(EjbRequestHandler.java:181)
所以我有这样的UserDAO:
@Stateless
public class UserDAO {
@PersistenceContext
private EntityManager em;
public void createUser(String name) {
// User user = new User();
// user.setName(name);
// em.persist(user);
// System.out.println("Maliiii");
}
}
当我评论EntityManager和@PersistenceContext时,TomEE无异常地运行。但是,只有通过删除注释和部署,我才能获得巨大的堆栈跟踪。在我切换到TomEE之前,我尝试使用glassfish并没有出现这个问题。但是,在应用程序管理器中设置jdbc连接池时出现问题,这就是我切换到tomee的原因。
的persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence-unit name="NewPersistenceUnit">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/bar"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.connection.password" value="root"/>
<!--<property name="hibernate.archive.autodetection" value="class"/>-->
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hbm2ddl.auto" value="create"/>
</properties>
</persistence-unit>
任何想法如何解决?
答案 0 :(得分:0)
首先想到的是,TomEE的标准安装具有JPA的OpenJPA实现,而不是hibernate的情况。如果是这种情况,请尝试从<provider>
中删除persistence.xml
。有一个版本的TomEE与Eclipselink(称为Plume),但没有正式版本的hibernate。如果你想要休眠,你可以将它作为一个依赖包含在你的WAR中。
但是,glassfish也不包含hibernate,所以你可能已经在WAR中休眠过了?
答案 1 :(得分:0)
正如@OndrejM所说tomcat使用apache open jpa作为它的JPA实现,所以你可以将你的提供者更改为
org.apache.openjpa.persistence.PersistenceProviderImpl
指定持久性提供程序实现
此外,您需要更改JDBC配置属性名称以使用OpneJpa而不是hibernate来像
**
<property name="openjpa.ConnectionDriverName"value="your value" />
<property name="openjpa.ConnectionURL" value="your value" />
<property name="openjpa.ConnectionUserName" value="your value" />
<property name="openjpa.ConnectionPassword" value="your value" />
**
答案 2 :(得分:0)
所以我发现了错误,这真的是一个愚蠢的错误。 由于我使用的是InteliJ,我正在查询&#34;用户&#34;来自ide的表。我也是从mysql查询它,但没有注意到更改。事实证明,jpa创造了一个&#34;用户&#34;和&#34;用户&#34; table(我尝试更改@Entity中的名称)以及它写入这两个表的所有时间。所以我在刷新&#34;表&#34;之后注意到这些表格。在MySql工作台中。感谢大家的帮助,我很抱歉这个愚蠢的问题:)