0

I am trying to deploy EAR in TomEE. Ear contains a WAR file and a JAR file. And inside the Jar file, under META-INF, I have the persistence.xml file. I added hibernate jars under Tomee/lib

When I start the tomee, I am getting following exception.

org.apache.openejb.OpenEJBException: Creating application failed: C:\apache-tomee-1.7.4-webprofile-without\apps\cmsear: org/hibernate/mapping/MappedSuperclass
        at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:843)
        at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:677)
        at org.apache.openejb.assembler.classic.Assembler.buildContainerSystem(Assembler.java:568)
        at org.apache.openejb.assembler.classic.Assembler.build(Assembler.java:464)
        at org.apache.openejb.OpenEJB$Instance.<init>(OpenEJB.java:151)
        at org.apache.openejb.OpenEJB.init(OpenEJB.java:309)
        at org.apache.tomee.catalina.TomcatLoader.initialize(TomcatLoader.java:256)
        at org.apache.tomee.catalina.ServerListener.install(ServerListener.java:167)
        at org.apache.tomee.catalina.ServerListener.lifecycleEvent(ServerListener.java:54)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
        at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
        at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:394)
        at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:110)
        at org.apache.catalina.startup.Catalina.load(Catalina.java:642)
        at org.apache.catalina.startup.Catalina.load(Catalina.java:667)
        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:498)
        at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:253)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:427)
Caused by: java.lang.NoClassDefFoundError: org/hibernate/mapping/MappedSuperclass
        at org.hibernate.ejb.metamodel.MetamodelImpl.buildMetamodel(MetamodelImpl.java:59)
        at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:83)
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:883)
        at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
        at org.apache.openejb.assembler.classic.EntityManagerFactoryCallable.call(EntityManagerFactoryCallable.java:64)
        at org.apache.openejb.assembler.classic.ReloadableEntityManagerFactory.createDelegate(ReloadableEntityManagerFactory.java:116)
        at org.apache.openejb.assembler.classic.ReloadableEntityManagerFactory.<init>(ReloadableEntityManagerFactory.java:102)
        at org.apache.openejb.assembler.classic.PersistenceBuilder.createEntityManagerFactory(PersistenceBuilder.java:154)
        at org.apache.openejb.assembler.classic.Assembler.loadPersistenceUnits(Assembler.java:982)
        at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:741)
        ... 20 more
Caused by: java.lang.ClassNotFoundException: org.hibernate.mapping.MappedSuperclass
        at org.apache.openejb.util.classloader.URLClassLoaderFirst.loadClass(URLClassLoaderFirst.java:136)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 30 more

I have tried configuring tomee and hibernate using the following link: http://tomee.apache.org/tomee-and-hibernate.html

Could anyone help me in fixing this exception? And please let me know if I need to provide any other information. Thanks.

Edit 1: Removed the jars from the WEB-INF/lib folder. And now getting the following exception:

INFO: Named query checking : enabled
Apr 24, 2018 11:29:31 AM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Apr 24, 2018 11:29:32 AM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
Apr 24, 2018 11:29:32 AM org.apache.openejb.assembler.classic.ReloadableEntityManagerFactory createDelegate
INFO: PersistenceUnit(name=JPADB, provider=org.hibernate.ejb.HibernatePersistence) - provider time 2509ms
Apr 24, 2018 11:29:32 AM org.apache.openejb.assembler.classic.Assembler destroyApplication
INFO: Undeploying app: C:\apache-tomee-1.7.4-webprofile-without\apps\cmsear
Apr 24, 2018 11:29:32 AM org.apache.openejb.assembler.classic.Assembler buildContainerSystem
SEVERE: Application could not be deployed:  C:\apache-tomee-1.7.4-webprofile-without\apps\cmsear
org.apache.openejb.OpenEJBException: Creating application failed: C:\apache-tomee-1.7.4-webprofile-without\apps\cmsear: org/hibernate/mapping/MappedSuperclass
        at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:843)
        at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:677)
        at org.apache.openejb.assembler.classic.Assembler.buildContainerSystem(Assembler.java:568)
        at org.apache.openejb.assembler.classic.Assembler.build(Assembler.java:464)
        at org.apache.openejb.OpenEJB$Instance.<init>(OpenEJB.java:151)
        at org.apache.openejb.OpenEJB.init(OpenEJB.java:309)
        at org.apache.tomee.catalina.TomcatLoader.initialize(TomcatLoader.java:256)
        at org.apache.tomee.catalina.ServerListener.install(ServerListener.java:167)
        at org.apache.tomee.catalina.ServerListener.lifecycleEvent(ServerListener.java:54)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
        at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
        at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:394)
        at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:110)
        at org.apache.catalina.startup.Catalina.load(Catalina.java:642)
        at org.apache.catalina.startup.Catalina.load(Catalina.java:667)
        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:498)
        at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:253)
        at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:427)
Caused by: java.lang.NoClassDefFoundError: org/hibernate/mapping/MappedSuperclass

EDIT 2 : Following are the jars that I have inside my tomee/lib :

hibernate-annotations-3.5.0.Final.jar
hibernate-commons-annotations-5.0.1.Final.jar
hibernate-core-3.5.0-Final.jar
hibernate-entitymanager-3.5.0-Final.jar
hibernate-jpa-2.1-api-1.0.0.Final.jar
hibernate-validator-4.2.0.Final.jar
hibernate-validator-annotation-processor-4.2.0.Final.jar

Edit 3 : Updated hibernate jars inside tomee/lib. Now the folder contains the following hibernate related jars.

hibernate-commons-annotations-5.0.1.Final.jar
hibernate-core-5.0.12-Final.jar
hibernate-entitymanager-5.0.12-Final.jar
hibernate-jpa-2.1-api-1.0.0.Final.jar
hibernate-validator-4.2.0.Final.jar
hibernate-validator-annotation-processor-4.2.0.Final.jar
jboss-logging-3.3.0.Final.jar

Edit 4 : My application.xml looks as follows:

  <module>
    <web>
      <web-uri>abc.war</web-uri>
      <context-root>abc</context-root>
    </web>
  </module>
  <module>
    <ejb>defEJB.jar</ejb>
  </module>
Mukund S
  • 31
  • 2
  • 9
  • Are you sure you added *all* the required Hibernate jars to TomEE? `org.hibernate.mapping.MappedSuperclass` is a member of `hibernate-core`, did you include that, too? Also, since Hibernate jars are to be loaded by TomEE, you need to make sure they are not duplicated in `WEB-INF\lib`. – crizzis Apr 23 '18 at 20:46
  • @crizzis I have **hibernate-core-3.3.3.GA.jar** inside **tomee/lib**. And Are you mentioning about the **WEB-INF/lib** of WAR ? – Mukund S Apr 24 '18 at 15:42
  • Yes, I meant the `WEB-INF/lib` of the WAR. In general, if you're building the WAR using Maven/Gradle, all container-provided dependencies should be declared `provided` or `compileOnly` – crizzis Apr 24 '18 at 16:20
  • @crizzis I removed the jar from the WEB-INF/lib and tried. Still I am getting the same error. – Mukund S Apr 24 '18 at 17:32
  • @crizzis Do I need to make any changes in persistence.xml file ? Please find my EDIT 1 in the question. – Mukund S Apr 24 '18 at 17:33
  • (1) Is there a particular reason why you are using a Hibernate version that old? (2) `org.hibernate.mapping.MappedSuperclass` first appears in `hibernate-core:3.5.0.Final` (`3.3.2.GA` does *not* contain such a class, and `3.3.3.GA` is not event present in the central Maven repo). For some reason, another piece of your code requires that class. Are you sure all Hibernate jars have the same version? I'd try upgrading them all to (at least) `3.5.0.Final` to see if the problem goes away – crizzis Apr 24 '18 at 18:42
  • @crizzis I have added the jars hibernate jars in EDIT 2. Could you please take a look at it and let me know if there is any problem with that? Because I am guessing that the issue is because of some incompatible versions. – Mukund S Apr 26 '18 at 15:46
  • Looks better (I'm not sure `hibernate-commons-annotations` is needed, and I believe JPA 2.1 is not supported by hibernate 3.5). Are you still getting the exact same error? If another class is now missing, you might want to look at the poms for [hibernate-entitymanager](http://central.maven.org/maven2/org/hibernate/hibernate-entitymanager/3.5.0-Final/hibernate-entitymanager-3.5.0-Final.pom) and [hibernate-core](http://central.maven.org/maven2/org/hibernate/hibernate-core/3.5.0-Final/hibernate-core-3.5.0-Final.pom) – crizzis Apr 26 '18 at 17:28
  • @crizzis Update the hibernate jars which you can see in Edit 3. Now EAR is getting deployed in tomee. But when I run the application, it says it cant find a class from EJB jar file. EAR contains a WAR and a EJB jar file. May I know why? And also if I need to provide hibernate.properties where do I need to include the file ? – Mukund S May 01 '18 at 15:18
  • Is the EJB module listed in `application.xml`? I'm not overly familiar with using 'pure' Hibernate, but I think `hibernate.properties` belongs in `src/main/resources` directly – crizzis May 01 '18 at 15:28
  • @crizzis Yes EJB is listed in application.xml. You can look at my Edit 4. And after deploying I can find the EJB jar file inside the Ear too. – Mukund S May 01 '18 at 15:38
  • Is the JAR name `defEJB.jar` or `defEJB-{version}.jar`? The name should match whatever is defined in `application.xml`. To strip the version, use one of the solutions described [here](https://stackoverflow.com/questions/33411621/how-to-remove-version-number-from-war-file) – crizzis May 01 '18 at 16:37
  • @crizzis It is just defEJB.jar. There is no version number specified in application.xml. – Mukund S May 01 '18 at 16:41
  • @crizzis I didnt define the classpath in MANIFEST.MF. Now it is able to access the classes inside EJB jar file. But now I got another problem. It is not able to access the classes which are inside the WAR file. – Mukund S May 01 '18 at 17:53

0 Answers0