views:

2414

answers:

2

Hi all,

I have been recently running into an issue in which my web application will not start properly and the stack trace doesn't indicate exactly what happened. I have been able to isolate it to an event listener that I wrote. Whenever I attempt to activate it, I get a very generic exception:

org.jboss.seam.InstantiationException: Could not instantiate Seam component: entityManagerFactory
    at org.jboss.seam.Component.newInstance(Component.java:2144)
    at org.jboss.seam.contexts.Contexts.startup(Contexts.java:304)
    at org.jboss.seam.contexts.Contexts.startup(Contexts.java:278)
    at org.jboss.seam.contexts.ServletLifecycle.endInitialization(ServletLifecycle.java:116)
    at org.jboss.seam.init.Initialization.init(Initialization.java:740)
    at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:36)
    at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:645)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:189)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:978)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:586)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:349)
    at org.mortbay.jetty.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:102)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
    at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:165)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:162)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
    at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:165)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
    at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:92)
    at org.eclipse.jetty.server.Server.doStart(Server.java:228)
    at org.mortbay.jetty.plugin.JettyServer.doStart(JettyServer.java:69)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
    at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:433)
    at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:377)
    at org.mortbay.jetty.plugin.JettyRunWarMojo.execute(JettyRunWarMojo.java:68)
    at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
    at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
    at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
    at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
    at org.codehaus.classworlds.Launcher.main(Launcher.java:375)

Now, I had this problem in the past, and that was caused by me trying to over optimize each entity class by making the setters and getters final. Hibernate needs to setup proxying for the entity classes so it can lazy load stuff, so if I make a setter/getter final, it can't do that.

The event listener I want to use essentially listens for persist and update events. When one happens, it is supposed to set the current date on a field annotated with the corresponding annotation to mark the field as requiring a current date to be set.

I am thinking that this is because I am running a newer version of javassist:

javassist:javassist:jar:3.11.0.GA:runtime

Has anyone run into this issue before?

I am running JBoss Seam 2.2.0.GA on Jetty 7.

persistence.xml (abbreviated version)

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
             version="1.0">
    <persistence-unit name="${jdbc.database}" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <non-jta-data-source>${jdbc.datasource.name}</non-jta-data-source>

        <class> ... classes go here </class>

        <exclude-unlisted-classes>true</exclude-unlisted-classes>
        <properties>
            <property name="hibernate.dialect" value="${hibernate.dialect}"/>
            <property name="hibernate.hbm2ddl.auto" value="${ddl.mode}"/>

            <property name="hibernate.show_sql" value="${hibernate.showSql}"/>
            <property name="format_sql" value="${hibernate.formatSql}"/>
            <property name="use_sql_comments" value="${hibernate.useSqlComments}"/>

            <property name="hibernate.jdbc.batch_versioned_data" value="true"/>

            <property name="hibernate.cache.provider_class" value="org.hibernate.cache.EHCacheProvider"/>

            <property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider"/>
            <property name="hibernate.cache.use_query_cache" value="true"/>
            <property name="hibernate.cache.provider_configuration_file_resource_path" value="/ehcache.xml"/>

            <property name="hibernate.connection.release_mode" value="after_transaction"/>
            <property name="hibernate.connection.autocommit" value="true"/>

            <!-- Current Date listeners -->
            <!--
            <property name="hibernate.ejb.event.pre-insert" value="org.hibernate.ejb.event.EJB3PersistEventListener,com.walterjwhite.listener.persistence.listener.SetCurrentDateListener"/>
            <property name="hibernate.ejb.event.pre-update" value="org.hibernate.ejb.event.EJB3MergeEventListener,com.walterjwhite.listener.persistence.listener.SetCurrentDateListener"/>
            -->

            <!-- Envers listeners -->
            <property name="hibernate.ejb.event.post-insert" value="org.hibernate.ejb.event.EJB3PostInsertEventListener,org.hibernate.envers.event.AuditEventListener"/>
            <property name="hibernate.ejb.event.post-update" value="org.hibernate.ejb.event.EJB3PostUpdateEventListener,org.hibernate.envers.event.AuditEventListener"/>
            <property name="hibernate.ejb.event.post-delete" value="org.hibernate.ejb.event.EJB3PostDeleteEventListener,org.hibernate.envers.event.AuditEventListener"/>
            <property name="hibernate.ejb.event.pre-collection-update" value="org.hibernate.envers.event.AuditEventListener"/>
            <property name="hibernate.ejb.event.pre-collection-remove" value="org.hibernate.envers.event.AuditEventListener"/>
            <property name="hibernate.ejb.event.post-collection-recreate" value="org.hibernate.envers.event.AuditEventListener"/>

            <!-- Hibernate Search -->
            <property name="hibernate.search.default.directory_provider" value="org.hibernate.search.store.FSDirectoryProvider"/>
            <property name="hibernate.search.default.indexBase" value="${application.directory}/lucene/indexes"/>
        </properties>
    </persistence-unit>
</persistence>

When I use Javassist 3.4.GA instead of 3.11.GA, I get this error.

java.lang.IllegalAccessError: tried to access class javassist.bytecode.StackMapTable$Writer from class org.jboss.seam.util.ProxyFactory
    at org.jboss.seam.util.ProxyFactory.makeConstructor(ProxyFactory.java:803)
    at org.jboss.seam.util.ProxyFactory.makeConstructors(ProxyFactory.java:685)
    at org.jboss.seam.util.ProxyFactory.make(ProxyFactory.java:565)
    at org.jboss.seam.util.ProxyFactory.createClass3(ProxyFactory.java:346)
    at org.jboss.seam.util.ProxyFactory.createClass2(ProxyFactory.java:325)
    at org.jboss.seam.util.ProxyFactory.createClass(ProxyFactory.java:284)
    at org.jboss.seam.Component.createProxyFactory(Component.java:2426)
    at org.jboss.seam.Component.getProxyFactory(Component.java:1513)
    at org.jboss.seam.Component.wrap(Component.java:1504)
    at org.jboss.seam.Component.instantiateJavaBean(Component.java:1442)
    at org.jboss.seam.Component.instantiate(Component.java:1359)
    at org.jboss.seam.Component.newInstance(Component.java:2122)
    at org.jboss.seam.contexts.Contexts.startup(Contexts.java:304)
    at org.jboss.seam.contexts.Contexts.startup(Contexts.java:278)
    at org.jboss.seam.contexts.ServletLifecycle.endInitialization(ServletLifecycle.java:116)
    at org.jboss.seam.init.Initialization.init(Initialization.java:740)
    at org.jboss.seam.servlet.SeamListener.contextInitialized(SeamListener.java:36)
    at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:645)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:189)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:978)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:586)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:349)
    at org.mortbay.jetty.plugin.JettyWebAppContext.doStart(JettyWebAppContext.java:102)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
    at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:165)
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:162)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
    at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:165)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
    at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:92)
    at org.eclipse.jetty.server.Server.doStart(Server.java:228)
    at org.mortbay.jetty.plugin.JettyServer.doStart(JettyServer.java:69)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:55)
    at org.mortbay.jetty.plugin.AbstractJettyMojo.startJetty(AbstractJettyMojo.java:433)
    at org.mortbay.jetty.plugin.AbstractJettyMojo.execute(AbstractJettyMojo.java:377)
    at org.mortbay.jetty.plugin.JettyRunWarMojo.execute(JettyRunWarMojo.java:68)
    at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
    at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
    at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
    at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
    at org.codehaus.classworlds.Launcher.main(Launcher.java:375)

Walter

+2  A: 

Hi,

My advice is:

Always generate your project by using Seam-gen

This way, you do not have to worry about libraries that your project needs.

Message is:

org.jboss.seam.InstantiationException: Could not instantiate Seam component: entityManagerFactory

Have you set up your EntityManagerFactory ?

If not, do as follows (I suppose you are not using JTA environment. So i will show you a RESOURCE_LOCAL EntityManagerFactory)

/WEB-INF/components.xml

<!--I AM USING 2.1 version-->
<!--SO I SUPPOSE YOU HAVE TO REPLACE 2.1 by 2.2-->
<components xmlns="http://jboss.com/products/seam/components"
        xmlns:core="http://jboss.com/products/seam/core"
        xmlns:persistence="http://jboss.com/products/seam/persistence"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation=
            "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd 
             http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd 
             http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd"&gt;

<!--SET UP A MANAGED EntityManagerFactory-->
<!--DEFAULT TO ScopeType.APPLICATION-->
<persistence:entity-manager-factory name="entityManagerFactory" persistence-unit-name="<PERSISTENCE_UNIT_NAME_MUST_MATCH_NAME_ATTRIBUTE_IN_PERSISTENCE.XML>"/>

<!--SET UP A MANAGED EntityManager-->
<!--DEFAULT TO ScopeType.CONVERSATION-->
<persistence:managed-persistence-context name="entityManager" entity-manager-factory="#{entityManagerFactory}" auto-create="true"/>

<!--SET UP SEAM TRANSACTION MANAGER-->
<!--IT TAKES CARE OF CALLING BEGIN AND COMMIT-->
<tx:entity-transaction entity-manager="#{entityManager}"/>

</components>

Notice when using auto-create attribute equal true, you do not have to set up create attribute in @In annotation

// You do not need to set up create attribute 
// because of auto-create atrribute in persistence:managed-persistence-context component
@In(create=true)
private EntityManager entityManager;

Takes care by using naming convention, EntityManager reference must match name attribute in persistence:managed-persistence-context component.

Now you have to define your /META-INF/persistence.xml

/META-INF/persistence.xml

<persistence-unit name="<PERSISTENCE_UNIT_NAME_GOES_HERE>" transaction-type="RESOURCE_LOCAL">
    // Set up properties here
</persistence-unit>

If you are using a data source that can be obtained by JNDI - you need to set up according your target application server (TOMCAT, JETTY etc), do as follows

/META-INF/persistence.xml

<persistence-unit name="<PERSISTENCE_UNIT_NAME_GOES_HERE>">
    <non-jta-data-source>jdbc/myAppDS</non-jta-data-source>
</persistence-unit>

And if you want to set up a current date, do as follows instead of using Hibernate event

<!--currentDate IS A BUILT-IN Seam component-->
<!--DEFAULT TO ScopeType.STATELESS-->
<!--ScopeType.STATELESS IS SIMILAR TO Spring prototype scope-->
<h:inputHidden value="#{currentDate}" rendered="false" binding="#{myBackingBean.currentDate}"/>

About final keyword, maybe you want to see I get a log message: reflection optimizer disabled

regards,

Arthur Ronald F D Garcia
Arthur, thanks for your comments. I don't use Seam-gen, I'm using Maven. I am doing everything that you had mentioned above except the auto-create. I don't believe that is the issue. The issue occurs on startup when it is creating the entity manager factory. Like I said, I've been working on this web application for months now and have deployed previous versions just fine. If I uncomment my custom entity listeners, that is when I get the problem, or when I have entities not setup properly. I am mainly concerned with not seeing the stack trace.
I have seen some issues about Seam 2.2 version. Because of that, i prefer to delay my update. If possible, show your persistence.xml file.
Arthur Ronald F D Garcia
If i use a seam-gen project, i do not have to worry about any missing library and i can use SeamTest which allows me to test without deploying.
Arthur Ronald F D Garcia
It is not a missing library, I think I might be using too new of a version of javassist? I'd have to test that theory to see exactly. I believe hibernate pulls in an older version (before it became part of jboss), and seam or something else pulls in a much newer version.
+2  A: 

Well, I didn't really get any good answers. In this particular instance that I had the problem, the problem was having an incorrect version of my dependencies configured. That is one of the negatives with having my projects split up as much as they are. I have to pay close attention to which version I'm using in each project.

In other cases, it seemed to me that I had issues with a Lucene configuration. In either case, I would prefer to see the stack trace so I can look at it and then, oops, I have a bad jar or something like that.

Walter

@Walter White Thank you for telling us what happened (+1)
Arthur Ronald F D Garcia