9

I have Eclipse Indigo that I use to develop a JSF 2 project using Glassfish 3 Open Source, this in my computer then in my EC2 instance too, in Amazon AWS, for both Glassfish's I created a JDBC Connection Pool to use with my JPA Entity Manager.

Locally my project works pretty fine, but when I deploy the project and try to execute the same form, which gets some values from the database that is running in the same instance EC2 that is running the GlassFIsh tough.

I receive this message:

enter image description here

serverError: class javax.faces.el.EvaluationException

I'm searching about it, but I don't found anything so far.

There's some configuration that I shoud do for it works ?

EDIT:

Here's the stacktrace:

javax.faces.FacesException: #{reportc.generateReport}: javax.ejb.EJBException
        at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
        at javax.faces.component.UICommand.broadcast(UICommand.java:315)
        at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
        at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
        at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
        at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
        at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
        at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
        at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
        at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
        at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
        at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
        at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
        at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
        at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
        at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
        at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
        at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
        at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
        at java.lang.Thread.run(Thread.java:636)
Caused by: javax.faces.el.EvaluationException: javax.ejb.EJBException
        at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
        at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
        ... 32 more
Caused by: javax.ejb.EJBException
        at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5193)
        at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5091)
        at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4879)
        at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2039)
        at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1990)
        at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:222)
        at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
        at $Proxy225.listLastMinutes(Unknown Source)
        at com.brainset.eao.__EJB31_Generated__LogEAO__Intf____Bean__.listLastMinutes(Unknown Source)
        at com.brainset.controller.ReportControl.getLog(ReportControl.java:234)
        at com.brainset.controller.ReportControl.generateReport(ReportControl.java:49)
        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 com.sun.el.parser.AstValue.invoke(AstValue.java:234)
        at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
        at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
        at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
        ... 33 more
Caused by: java.lang.IllegalStateException: Attempting to execute an operation on a closed EntityManagerFactory.
        at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.verifyOpen(EntityManagerFactoryDelegate.java:305)
        at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:276)

EDIT 2: This is how I'm using the EntityManager:

@Stateless(mappedName = "logEAO")
@LocalBean
public class LogEAO {
    @PersistenceContext
    private EntityManager em;

    public LogEAO() {}


    public Log find(int id) {
        return em.find(Log.class, id);
    }
    // .. 
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Valter Silva
  • 16,446
  • 52
  • 137
  • 218
  • This alert is typical for Mojarra (with project stage set to `Development`) when sending an ajax request resulted in an exception during invoke action. You can find the full stacktrace in server log. Or, (temporarily) disable `` so that you get the HTTP 500 error page in its entirety. For better exception handling of ajax requests, check [this](http://balusc.blogspot.com/2012/03/full-ajax-exception-handler.html). Once you have the full stacktrace, include it in your question. Then we can explain the cause and propse the solution based on the stacktrace. – BalusC Mar 30 '12 at 17:07
  • @BalusC You're right my project stage is set to development, should remove it ? I got the log from glassfish as you told me, here it is in my post update. – Valter Silva Mar 30 '12 at 17:34
  • No if you remove it, you won't get this alert anymore so you won't get **any** notification anymore that something failed during ajax request. This doesn't solve the underlying problem. – BalusC Mar 30 '12 at 17:52
  • What happen if you stop and start glassfish. After start try your site again, I have spent a lot time with issues like this. There is a bug in glassfish 3.1 on re-deployment. – edze Mar 30 '12 at 18:14

3 Answers3

22

If you are using Glassfish server, restarting the server did it for me.

Eddie Martinez
  • 13,582
  • 13
  • 81
  • 106
9

From your stacktrace:

Caused by: java.lang.IllegalStateException: Attempting to execute an operation on a closed EntityManagerFactory.

Your EJB code looks all right. This is more likely a Glassfish bug or misconfiguration:


This can only mean that you're manually managing the EntityManagerFactory (and EntityManager) instead of letting the container do the job by just @PersistenceContext.

The EntityManagerFactory is intented to be created only once on webapp's startup, reused throughout the entire webapp's lifetime and closed on webapp's shutdown. It should not be closed somewhere halfway or be serialized and reused for a next restart cycle.

Since you're apparently targeting Glassfish, I would strongly recommend to not manage it yourself, but letting Glassfish do the job. You end up with much simpler EJB code without all the hassle to manage transactions manually.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I saw your link and the only difference comparing with the example that you indicates is that don't have `@LocalBean`, should it remove it ? – Valter Silva Mar 30 '12 at 18:03
  • Wait, as per the EJB code snippet in your question update you aren't manually getting the `EntityManager`, but just using `@PersistenceContext` to let the container inject it. So you're doing it the right way. This is maybe a bug or misconfiguration of Glassfish. Do you have full admin control over it? Are you sure that the JTA datasource configuration in persistence.xml and Glassfish admin console is 100% all right? – BalusC Mar 30 '12 at 18:06
  • I have full admin control of glassfish, I'm thinking to delete it and start everything again. The JTA datasource it's all right because I made the ping and it show me that everything was all right. The same thing for the persistence.xml. – Valter Silva Mar 30 '12 at 18:11
  • Just restarting glassfish manually did it. Thanks for the hints. Seems like my version had this bug. – Mafii May 01 '18 at 22:45
3

I had this problem and found a solution.

The problem is that eclipse (with the glassfish plugin) starts/stops only the domain and not the database.

Steps:

  1. Start database from command-line/outside eclipse
  2. Start server (domain) in eclipse
  3. Deploy application with @PersistenceContext injection --> works

Details:

I exited eclipse - this stopped the glassfish server. Then shutdown the machine - stopped the database. On restart, opened eclipse, started server and tried deploying the same app. Failed with error:

Deployment Error for module xxx
Error occurred during deployment: Exception while preparing the app :
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): 
org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: Error in allocating a connection.
Cause: Connection could not be allocated because: java.net.ConnectException :
Error connecting to server localhost on port 1527 with message Connection refused

The reason being database was not started. So started database from command-line. Got the error

java.lang.IllegalStateException: Attempting to execute an operation on a closed EntityManagerFactory

Then followed the steps above and it worked.


EDIT The above steps fixes the problem sometimes, but it also seems a known issuein GF 3.0/3.1: http://java.net/jira/browse/GLASSFISH-17295

Another option is to redeploy the application from admin console as mentioned here: http://richardchesterwood.blogspot.in/2011/09/javaee-course-ships-with-copy-of-javaee.html

gammay
  • 5,957
  • 7
  • 32
  • 51