Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6568753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:31:08+00:00 2026-05-25T14:31:08+00:00

I’m developing EAR application using EJB, JPA and Vaadin for web interface. The application

  • 0

I’m developing EAR application using EJB, JPA and Vaadin for web interface. The application server – GlassFish 3.1.1.

File DofApplicationServlet.java

package test.servlet;

import com.vaadin.Application;
import com.vaadin.terminal.gwt.server.AbstractApplicationServlet;
import test.ejb.TestBean;

import javax.ejb.EJB;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

public class DofApplicationServlet extends AbstractApplicationServlet {
    @EJB
    private TestBean testBean;

    @PersistenceUnit(name="mainPU")
    private EntityManagerFactory emf;

    @Override
    protected Application getNewApplication(HttpServletRequest httpServletRequest) throws ServletException {
        return new DofApplication(testBean, emf);
    }

    @Override
    protected Class<? extends Application> getApplicationClass() throws ClassNotFoundException {
        return DofApplication.class;
    }
}

File DofApplication.java

package test.servlet;

import com.vaadin.Application;
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
import com.vaadin.ui.TextField;
import com.vaadin.ui.Window;
import test.ejb.TestBean;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Query;

public class DofApplication extends Application  {
    private TestBean testBean;
    private Label labelResult;
    private Label labelCount;
    private Label labelUser;
    private int counter;
    private EntityManagerFactory emf;

    public DofApplication(TestBean testBean, EntityManagerFactory emf) {
        this.testBean = testBean;
        this.emf = emf;
    }

    @Override
    public void init() {
        Window wnd = new Window();
        final TextField tfLogin = new TextField("login");
        wnd.addComponent(tfLogin);

        final TextField tfPass = new TextField("password");
        wnd.addComponent(tfPass);

        labelResult = new Label("result");
        wnd.addComponent(labelResult);

        labelCount = new Label("Counter");
        wnd.addComponent(labelCount);

        labelUser = new Label("Current user");
        wnd.addComponent(labelUser);

        Button btnLogin = new Button("Login");
        wnd.addComponent(btnLogin);

        Button btnSess = new Button("Session");
        wnd.addComponent(btnSess);


        btnLogin.addListener(new Button.ClickListener() {
            public void buttonClick(Button.ClickEvent clickEvent) {
                boolean auth = testBean.checkOracleConnection(tfLogin.getValue().toString(), tfPass.getValue().toString());
                if (auth) {
                    labelResult.setCaption("auth ok " + tfLogin.getValue().toString());
                    labelUser.setCaption("Current username: " + tfLogin.getValue().toString());
                }  else {
                    labelResult.setCaption("auth fail");
                    labelUser.setCaption("Current username: NONE");
                }

            }
        });

        btnSess.addListener(new Button.ClickListener() {
            public void buttonClick(Button.ClickEvent clickEvent) {
                EntityManager em = emf.createEntityManager(); // <-- emf is not null here in debugger, but call always returns exception
                Query q = em.createQuery("SELECT c FROM CountryEntity c");

            }
        });


        setMainWindow(wnd);
    }


}

And exception I got in btnSess click handler:

[#|2011-09-09T17:42:51.769+0600|SEVERE|glassfish3.1.1|com.vaadin.Application|_ThreadID=20;_ThreadName=Thread-2;|Terminal error:
com.vaadin.event.ListenerMethod$MethodException
Cause: java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName mainPU
    at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:510)
    at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:164)
    at com.vaadin.ui.AbstractComponent.fireEvent(AbstractComponent.java:1193)
    at com.vaadin.ui.Button.fireClick(Button.java:539)
    at com.vaadin.ui.Button.changeVariables(Button.java:206)
    at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariableBurst(AbstractCommunicationManager.java:1299)
    at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariables(AbstractCommunicationManager.java:1219)
    at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:735)
    at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(CommunicationManager.java:296)
    at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:501)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    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:662)
Caused by: java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName mainPU
    at com.sun.enterprise.container.common.impl.EntityManagerFactoryWrapper.getDelegate(EntityManagerFactoryWrapper.java:100)
    at com.sun.enterprise.container.common.impl.EntityManagerFactoryWrapper.createEntityManager(EntityManagerFactoryWrapper.java:110)
    at test.servlet.DofApplication$2.buttonClick(DofApplication.java:86)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:490)
    ... 35 more
|#]

But, in debugger I see the following:

debugger

Ear file structure

ear.ear
-- META-INF
---- application.xml
---- persistence.xml
-- ejb.jar
-- war.war
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:31:09+00:00Added an answer on May 25, 2026 at 2:31 pm

    I think this…

    protected Application getNewApplication(HttpServletRequest httpServletRequest) throws ServletException {
        return new DofApplication(testBean, emf);
    }
    

    … may cause problems here. The container will inject an entity manager factory which may be different for subsequent requests. So: if you create an instance of DofApplication and pass in that emf, you might call createEntityManager() on an invalid emf.

    To test this you could try to get the em like so within init():

    EntityManagerFactory emf = Persistence.createEntityManagerFactory("mainPU");
    em = emf.createEntityManager();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have just tried to save a simple *.rtf file with some websites and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
i want to parse a xhtml file and display in UITableView. what is the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.