0

I have an EJB application that is currently deployed on TomEE 1.7.4 with OpenJDK 7 inside a docker container (openjdk 7, TomEE, and my war).

Note: The Jar files that I added within TomEE lib folder are reconized by the application, because I had some errors that has been solved after adding those Jar files.

The error log

INFO: PersistenceUnit(name=manager1, provider=org.hibernate.jpa.HibernatePersistenceProvider) - provider time 2214ms
Apr 25, 2018 5:35:21 PM org.apache.openejb.assembler.classic.Assembler destroyApplication
INFO: Undeploying app: /usr/local/tomee/webapps/myapp
Apr 25, 2018 5:35:21 PM org.apache.catalina.core.ContainerBase removeChild
SEVERE: ContainerBase.removeChild: destroy: 
org.apache.catalina.LifecycleException: An invalid Lifecycle transition was attempted ([before_destroy]) for component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/myapp]] in state [STARTING_PREP]
    at org.apache.catalina.util.LifecycleBase.invalidTransition(LifecycleBase.java:401)
    at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:291)
    at org.apache.catalina.core.ContainerBase.removeChild(ContainerBase.java:1038)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.undeploy(TomcatWebAppBuilder.java:1537)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.undeploy(TomcatWebAppBuilder.java:1518)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.undeployWebApps(TomcatWebAppBuilder.java:762)
    at org.apache.openejb.assembler.classic.Assembler.destroyApplication(Assembler.java:1982)
    at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:839)
    at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:677)
    at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1261)
    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:5472)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1091)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1980)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:473)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:622)
    at java.lang.Thread.run(Thread.java:748)

Apr 25, 2018 5:35:21 PM org.apache.tomee.catalina.TomcatWebAppBuilder startInternal
SEVERE: Unable to deploy collapsed ear in war StandardEngine[Catalina].StandardHost[localhost].StandardContext[/myapp]
org.apache.openejb.OpenEJBException: Creating application failed: /usr/local/tomee/webapps/myapp: javax.persistence.Table.indexes()[Ljavax/persistence/Index;
    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.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1261)
    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:5472)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:899)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:875)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1091)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1980)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:473)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1152)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:622)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoSuchMethodError: javax.persistence.Table.indexes()[Ljavax/persistence/Index;
    at org.hibernate.cfg.annotations.EntityBinder.processComplementaryTableDefinitions(EntityBinder.java:973)
    at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:824)
    at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3845)
    at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3799)
    at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1412)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
    at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:425)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:849)
    at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:152)
    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)

List of Jar added to TomEE lib folder:

  • mysql:mysql-connector-java:5.1.22
  • org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final
  • org.hibernate:hibernate-entitymanager:4.3.9.Final
  • org.hibernate:hibernate-core:4.3.9.Final
  • org.hibernate.common:hibernate-commons-annotations:4.0.5.Final
  • org.jboss:jandex:1.1.0.Final
  • org.jboss.logging:jboss-logging:3.1.3.GA
  • org.javassist:javassist:3.18.1-GA
  • antlr:antlr:2.7.7
  • dom4j:dom4j:1.6.1

Although, I tried to deploy other apps within this docker image and every think works as expected.

  • Dockerfile added @EngineerDollery – Zied Yaich Apr 25 '18 at 17:46
  • you are missing the actual exception message from this question. Look further in the error logs. I don't think this is a Docker issue, your app fails to deploy for some reason or another - we cannot know why since that information is missing from this question. – eis Apr 25 '18 at 17:49
  • To further complicate things, you're deploying a war to a webapps directory, so this looks like a webapp, not an EJB app. Can you confirm? If it is simply a webapp then I highly recommend moving this to spring-boot and saving yourself years of heartache. – Software Engineer May 02 '18 at 14:25
  • I reviewed then removed your dockerfile from the question. It's fine and not relevant in the end as this is a java/jpa issue, not a docker issue. – Software Engineer May 02 '18 at 14:30
  • Okay, the app that I'm deploying has been in production for a couple of years, I'm just changing the deployment method to be dockerized when I faced this issue. So, Changing the technology or upgrading JAVA, TomEE version aren't options. Regarding those conditions I can't find a better solution, Please if you have any proposal based on those facts. Be my guest – Zied Yaich May 04 '18 at 12:26
  • You don't need to change anything to make this work in Docker. Neither your app nor TomEE will ever know that they are in a container and you don't do anything differently because of the container. From this perspective, it's remarkably similar to running in a VM. The problem you have is simply a java problem, not a docker problem. The problem you're facing is due to poor app factoring in the first place. You should completely replicate the running system in the container, as is, not rebuild it from source -- use existing binaries, because old source is hard to run, as you've discovered. – Software Engineer May 07 '18 at 14:30

3 Answers3

1

TLDR; your TomEE version does not support the apis you seem to be using.

I would go with upgrading TomEE, so you would get proper support for the apis you want to use. Other solutions are just workarounds that might break in numerous ways as they are not supported.


A bit longer answer:

This looks java app dependency problem/version conflict for me: see this thread for similar error message and its cause. The dependencies you've added depend on javax.persistence spec 2.1, but based on the stack trace your app seems to be using older apis.

You seem to want to use Java Persistence API 2.1, that comes with Java EE 7. Java EE 6 contains Java Persistence API 2.0.

Version of TomEE you're using, Apache TomEE 1.7.4, supports only Java EE 6 and thus Persistence API 2.0, and it was last version not supporting Java EE 7:

From this point on the TomEE community will be focusing most of it's efforts on TomEE 7.0.0, which will be the first TomEE Java EE 7 driven version running on Apache Tomcat 8.x.

So an upgrade of TomEE would be in order.

eis
  • 51,991
  • 13
  • 150
  • 199
  • Yes, I excluded all the dependencies that could make a conflict in my pom.xml. The real issue is the jars in tomEE lib folder, still contain dependencies that holds an older api, I don't know how to ignore those libs or force jpa 2.1 jar over them. – Zied Yaich Apr 26 '18 at 12:25
  • @ZiedYaich I think they contain dependencies because tomEE doesn't officially support newer version. Since there is no support, I'm not sure you would be able to get that setup to work without such issues. – eis Apr 26 '18 at 12:45
0

TomEE comes with OpenJPA as persistence engine. You can change to Hibernate but you have to follow this guide

Extending the ClassPath is a bad solution although it does the job.

fxrobin
  • 590
  • 3
  • 9
-1

I fugured it out, the solution is to create a "setenv.sh" file in TomEE bin directory with the CLASSPATH of the "jpa 2.1" jar file.

setenv.sh

#!/bin/sh
CLASSPATH=/usr/local/tomee/lib/hibernate-jpa-2.1-api-1.0.0.Final.jar
  • This is quite a poor solution because you have brute-forced the jar onto the path. You have no control over package priority resolution in TomEE and this may be working by pure luck on the systems you have tested it on, you have not 'managed' your dependencies, you have stepped outside the 'maven' build and deploy model, and you have forced reconfiguration of the server so that it can only ever work for your app and your app alone. – Software Engineer May 02 '18 at 14:20
  • I suspect that you're doing this because you've listed this dependency as optional in your maven pom. If you remove the scope the jar will be bundled correctly with your app and TomEE's class-loader will ensure that your app uses the correct jar. – Software Engineer May 02 '18 at 14:32
  • Okay, the app that I'm deploying has been in production for a couple of years, I'm just changing the deployment method to be dockerized when I faced this issue. So, Changing the technology or upgrading JAVA, TomEE version aren't options. Regarding those conditions I can't find a better solution, Please if you have any proposal based on those facts. Let me know – Zied Yaich May 04 '18 at 12:28