Coming Up for Air

A Seam+JPA/Hibernate on OC4J Maven 2 Archetype

As a follow-up to my entry on getting a Seam and JPA/Hibernate application running on OC4J, I now have an alpha release of a Maven 2 archetype available for use and testing, with heavy emphasis on testing.

Using the archetype is pretty simple (assuming you know how to use Maven 2 archetypes in general):

mvn archetype:create -DarchetypeGroupId=com.steeplesoft.maven.archetypes
    -DarchetypeArtifactId=seam-jpa-oc4j -DarchetypeVersion=1.0-alpha

What this gets you is a multi-module project, such as what was described in the aforementioned article, with (hopefully) working examples of a JPA entity bean, a HSQL-based PersistenceUnit, and a simple JSF (Facelets), all wired together via Seam. Chances are good that you’ll want to change the package name and structure to match your project and organization’s needs, but, if you’re like me, having these examples to copy and paste will help when creating a new project. :)

This is by no means perfect. Given my newness to Maven, the archetype itself could probably use some help, <strike>but there’s something more serious to consider at the moment involving OC4J. If you create the project as described above, deploy the resulting EAR file and hit the web context, you should see that the application works fine. If you try to redeploy the application, you’ll see an error message like this in the web console (formatted for readability)</strike>(this is been fixed):

Operation failed with error: java.lang.IllegalStateException:
    ClassLoader "myapp.web.myapp-web-1.0:0.0.0"
    (from in /oc4j/j2ee/home/applications/myapp/myapp-web-1.0/):
    This loader has been closed and should not be in use.

The server console will show something like this:

oracle.oc4j.admin.internal.DeployerException: java.lang.IllegalStateException: ClassLoader "myapp.web.myapp-web-1.0:0.0.0" (from <web-module> in /oc4j/j2ee/home/applications/myapp/myapp-web-1.0/): This loader has been closed and should not be in use.
      at org.hibernate.ejb.Ejb3Configuration.configure(
      at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(
      at javax.persistence.Persistence.createEntityManagerFactory(
      at javax.persistence.Persistence.createEntityManagerFactory(
      at org.jboss.seam.persistence.EntityManagerFactory.createEntityManagerFactory(
      at org.jboss.seam.persistence.EntityManagerFactory.startup(
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(
      at java.lang.reflect.Method.invoke(
      at org.jboss.seam.util.Reflections.invoke(
      at org.jboss.seam.util.Reflections.invokeAndWrap(
      at org.jboss.seam.Component.callComponentMethod(
      at org.jboss.seam.Component.callCreateMethod(
      at org.jboss.seam.Component.newInstance(
      at org.jboss.seam.contexts.Contexts.startup(
      at org.jboss.seam.contexts.Contexts.startup(
      at org.jboss.seam.contexts.ServletLifecycle.endInitialization(
      at org.jboss.seam.init.Initialization.init(
      at org.jboss.seam.servlet.SeamListener.contextInitialized(
      at com.evermind.server.http.HttpApplication.initDynamic(
      at com.evermind.server.http.HttpApplication.<init>(
      at com.evermind.server.ApplicationStateRunning.getHttpApplication(
      at com.evermind.server.Application.getHttpApplication(
      at com.evermind.server.http.HttpSite$HttpApplicationRunTimeReference.createHttpApplicationFromReference(
      at com.evermind.server.http.HttpSite$HttpApplicationRunTimeReference.<init>(
      at com.evermind.server.http.HttpSite.addHttpApplication(
      at oracle.oc4j.admin.internal.WebApplicationBinder.bindWebApp(
      at oracle.oc4j.admin.internal.WebApplicationBinder.bindWebApp(
      at oracle.oc4j.admin.internal.ApplicationDeployer.bindWebApp(
      at oracle.oc4j.admin.internal.ApplicationDeployer.doDeploy(
      at oracle.oc4j.admin.internal.DeployerBase.execute(
      at oracle.oc4j.admin.jmx.server.mbeans.deploy.OC4JDeployerRunnable.doRun(
      at com.evermind.util.ReleasableResourcePooledExecutor$

The only way I’ve found to fix that is to restart the app server, which is, of course, extremely ugly. Making this work on OC4J has been extremely trying, and this is just one more example of the pain I’ve put myself through. Since the contract dictates this container, though, I have little choice. :) At any rate, I’m going to try to work around this by creating one or more shared libraries on the app server and see what that gets me. I’ll report back what I find.

In the meantime, you can find the archetype in my (new) Maven repo (when the DNS finally propagates), or in its (experimental) Mercurial repository.

tags: JPA Maven OC4J Seam


Sample quote

Quote source