我想配置一个简单的JPA项目,我使用的是Wildfly 8,数据源是在standalone.xml中配置的。
<datasource jta="true" jndi-name="java:jboss/datasources/postgresql" pool-name="postgreSql" enabled="true" use-ccm="true">
<connection-url>jdbc:postgresql://localhost:5432/sell</connection-url>
<driver-class>org.postgresql.Driver</driver-class>
<driver>postgres</driver>
<security>
<user-name>postgres</user-name>
<password>sell</password>
</security>
</datasource>
在Web项目中,我像这样配置persistence.xml文件
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd“&GT;
<persistence-unit name="sellAppPersistenceUnit"
transaction-type="RESOURCE_LOCAL">
<jta-data-source>java:jboss/datasources/postgresql</jta-data-source>
<class>br.com.sell.app.orm.Usuario</class>
</persistence-unit>
但是,当我添加 br.com.sell.app.orm.Usuario 时,我在项目启动时遇到错误,错误表示出现了hibernate问题 org / hibernate / proxy / HibernateProxy ,但我不使用hibernate。
13:17:50,738 ERROR [org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer] (ServerService Thread Pool -- 58) HHH000142: Javassist Enhancement failed: br.com.sell.app.orm.Usuario: java.lang.RuntimeException: by java.lang.NoClassDefFoundError: org/hibernate/proxy/HibernateProxy
at javassist.util.proxy.ProxyFactory.createClass3(ProxyFactory.java:515)
at javassist.util.proxy.ProxyFactory.createClass2(ProxyFactory.java:492)
at javassist.util.proxy.ProxyFactory.createClass1(ProxyFactory.java:428)
at javassist.util.proxy.ProxyFactory.createClass(ProxyFactory.java:400)
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.getProxyFactory(JavassistLazyInitializer.java:162)
at org.hibernate.proxy.pojo.javassist.JavassistProxyFactory.postInstantiate(JavassistProxyFactory.java:67)
at org.hibernate.tuple.entity.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:224)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:212)
at org.hibernate.tuple.entity.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:80)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructTuplizer(EntityTuplizerFactory.java:135)
at org.hibernate.tuple.entity.EntityTuplizerFactory.constructDefaultTuplizer(EntityTuplizerFactory.java:188)
at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:403)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:520)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:148)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
为什么我可以解决这个问题?
pom.xml文件:
http://maven.apache.org/xsd/maven-4.0.0.xsd“&GT; 4.0.0 br.com.sell.app sellApp 0.0.1-SNAPSHOT POM sellApp 后端休息销售应用
<modules>
<module>sellAppEndpoint</module>
<module>sellAppWeb</module>
<module>sellAppCors</module>
<module>sellAppDto</module>
<module>sellAppOrm</module>
<module>sellAppJpa</module>
</modules>
<dependencies>
<!-- para importar pacotes javax.* para o REST -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.3.0.SP1</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.0.0.Final</version>
</dependency>
</dependencies>
答案 0 :(得分:0)
您的问题似乎是由于声明了不一致的依赖关系 - 版本5.0.0中的hibernate-entitymanager需要hibernate-core 5.0.0,但您强制在版本3.3.0.SP1中使用hibernate-core。版本3.3.0.SP1中不存在类org.hibernate.proxy.HibernateProxy
。由于hibernate-entitymanager声明了对hibernate-core的传递依赖,你可以删除对hibernate-core的依赖。
此外,Wildfly 8已经包含了hibernate(版本4.3),因为它必须按规范提供Java EE功能。你可以在Wildfly上使用hibernate,这是更标准的,除非你不需要hibernate 5.0的特殊功能。在这种情况下,还要从pom.xml中删除hibernate-entitymanager依赖项,并且您的代码仍然有用。