5 Replies Latest reply on Dec 3, 2013 7:17 AM by Stuart Douglas

    Calling Empty Constructor in Jboss 7.1.1

    Sreedhar UKD Newbie

      Hi

       

      I wanted replace my code from Jboss 4.0 to Jboss 7.1.1 , in Jboss 7.1.1  when we call an object from stateful session bean class every time

      it is invoking an empty constructor where it is not happening in Jboss 4.0. Did any one know the reason and what's new in Jboss 7.1.1

       

      Home Interface

      =============

       

      package Books;

      import javax.ejb.EJBHome;

      import java.rmi.RemoteException;

      import javax.ejb.CreateException;

      public interface BookHome extends EJBHome{

       

        public Book create() throws RemoteException,CreateException;

      }

       

      Remote Interface

      =================

       

      package Books;

      import javax.ejb.EJBObject;

       

       

      import java.rmi.RemoteException;

      import java.util.Vector;

      public interface Book extends EJBObject{

       

       

       

        public String addBook() throws RemoteException;

        public General getGeneral() throws RemoteException;

       

      }

       

      Session Bean (Stateful)

      ====================

      package Books;

      import javax.ejb.SessionBean;

      import java.util.Vector;

      import javax.ejb.SessionContext;

      import javax.naming.InitialContext;

       

       

       

       

      public class BookBean implements SessionBean,java.io.Serializable{

       

       

        Vector shelf;

        int a,b;

        private General g;

        public BookBean()

        {

       

        }

       

        public void ejbCreate()

        {

       

        System.out.println("Calling EJB Create method ========");

       

        g =new General(this);

       

        }

       

        public String addBook()

        {

        System.out.println(" Addition of two Numbers ");

       

       

        return String.valueOf(a+b);

        }

        public General getGeneral()

        {

        return g;

        }

        public void ejbRemove()

        {

        System.out.println("Calling ejbRemove method ==========");

        }

        public void ejbActivate()

        {

        System.out.println("Calling ejbActivate method ===========");

        }

        public void ejbPassivate()

        {

        System.out.println("calling ejbPassivate method ==========");

        }

        public void setSessionContext(SessionContext sc)

        {

        System.out.println("calling sessioncontext object =======");

        }

       

       

      }

       

       

      General Class (calling from the Session Bean)

      =================================

       

      package Books;

      public class General implements java.io.Serializable{

        BookBean bb;

        int a=10;

        public General()

        {

        System.out.println("CallingEmptyConstructor in General");

        a=20;

        }

        public General(BookBean bb)

        {

        this.bb=bb;

        System.out.println("The BookBean Curren Object"+bb.toString());

        System.out.println("Integer Variable Value is"+a);

        }

       

        public void show()

        {

        System.out.println("The content in the General Class");

        System.out.println("Integer Variable Value is "+a);

        }

       

      }

       

      jboss.xml

      ===================

       

      <?xml version="1.0" encoding="UTF-8"?>

      <jboss>

      <enterprise-beans>

      <session>

      <ejb-name>book</ejb-name>

      <jndi-name>Books.BookHome</jndi-name>

      </session>

       

      ejb-jar.xml

      ==================

       

       

        <display-name>BookCatalog</display-name>

        <enterprise-beans>

        <session>

        <ejb-name>book</ejb-name>

        <home>Books.BookHome</home>

        <remote>Books.Book</remote>

        <ejb-class>Books.BookBean</ejb-class>

        <session-type>Stateful</session-type>

        <transaction-type>Container</transaction-type>

       

        </session>

       

        </enterprise-beans>

       

      </ejb-jar>

       

       

      </enterprise-beans>

      </jboss>

       

       

      Client  (jsp file)

      ===================================

      <html>

      <head>

      </head>

      <body>

       

       

      <%@page import="Books.Book" %>

      <%@page import="Books.BookHome" %>

      <%@page import="javax.naming.InitialContext" %>

       

       

      <%

        try {

          InitialContext ctx = new InitialContext();

          BookHome home = (BookHome) ctx.lookup("java:app/BookCatalog.jar/book!Books.BookHome");

          int a=Integer.parseInt(request.getParameter("n1"));

          int b=Integer.parseInt(request.getParameter("n2"));

         

          Book book = home.create();

         

           System.out.println("Book class ===============================>"+book);  

          book.getGeneral().show();

          System.out.println("book.getGeneral()===="+book.getGeneral());

        }

       

       

        catch (Exception e) {

          out.print(e.getMessage());

        }

      %>

      </body>

      </html>

       

       

       

      If I execute this code in Jboss 4.0 empty constructor is not calling when it loads the object of General class

       

      Jboss 4.0

      ===========

       

      calling sessioncontext object =======

      Calling EJB Create method ========

      The BookBean Curren ObjectBooks.BookBean@1960caa

      Integer Variable Value is10

      Book class ===============================>Books.BookHome:hokz806s-4

      The content in the General Class

      Integer Variable Value is 10

      book.getGeneral()====Books.General@170209f

       

       

      but in the case of Jboss 7.1.1 it is calling empty constructor

       

      Jboss 7.1.1

      ============

      calling sessioncontext object =======

      Calling EJB Create method ========

      The BookBean Curren ObjectBooks.BookBean@5a138f

      Integer Variable Value is10

      Book class ===============================>Proxy for remote EJB StatefulEJBLocator{appName='sumear', moduleName='BookCatalog.jar', distinctName='', beanName='book', view='interface Books.Book', sessionId='{[-88, -110, 60, 15, 113, 127, 71, -127, -96, 6, 10, -106, -61, -23, 5, 33]}'}

      CallingEmptyConstructor in General

      The content in the General Class

      Integer Variable Value is 10

      CallingEmptyConstructor in General

      book.getGeneral()====Books.General@16fbd74

        • 1. Re: Calling Empty Constructor in Jboss 7.1.1
          Wolf-Dieter Fink Master

          Maybe this is more an JDK than an JBoss issue but I'm not sure as I expect that the () constructor should be called before.

           

          But you might add a stacktrace in the constructor to see the calling stack. Simple use new Exception() and call printStackTrace() for it without throwing it and you should see it.

          • 2. Re: Calling Empty Constructor in Jboss 7.1.1
            Sreedhar UKD Newbie

            14:04:25,693 ERROR [stderr] (http--127.0.0.1-80-5) java.lang.Exception

            14:04:25,693 ERROR [stderr] (http--127.0.0.1-80-5)      at Books.General.<init>(General.java:8)

            14:04:25,693 ERROR [stderr] (http--127.0.0.1-80-5)      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

            14:04:25,693 ERROR [stderr] (http--127.0.0.1-80-5)      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.

            java:57)

            14:04:25,693 ERROR [stderr] (http--127.0.0.1-80-5)      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAcces

            sorImpl.java:45)

            14:04:25,693 ERROR [stderr] (http--127.0.0.1-80-5)      at java.lang.reflect.Constructor.newInstance(Constructor.java:526)

            14:04:25,693 ERROR [stderr] (http--127.0.0.1-80-5)      at org.jboss.marshalling.reflect.ReflectiveCreator.create(ReflectiveCreator.java:107)

            14:04:25,693 ERROR [stderr] (http--127.0.0.1-80-5)      at org.jboss.marshalling.cloner.SerializingCloner.clone(SerializingCloner.java:248)

            14:04:25,693 ERROR [stderr] (http--127.0.0.1-80-5)      at org.jboss.marshalling.cloner.SerializingCloner.clone(SerializingCloner.java:135)

            14:04:25,693 ERROR [stderr] (http--127.0.0.1-80-5)      at org.jboss.as.ejb3.remote.LocalEjbReceiver.clone(LocalEjbReceiver.java:225)

            14:04:25,693 ERROR [stderr] (http--127.0.0.1-80-5)      at org.jboss.as.ejb3.remote.LocalEjbReceiver.clone(LocalEjbReceiver.java:216)

            14:04:25,693 ERROR [stderr] (http--127.0.0.1-80-5)      at org.jboss.as.ejb3.remote.LocalEjbReceiver.processInvocation(LocalEjbReceiver.java:18

            8)

            14:04:25,693 ERROR [stderr] (http--127.0.0.1-80-5)      at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationConte

            xt.java:179)

            14:04:25,693 ERROR [stderr] (http--127.0.0.1-80-5)      at org.jboss.ejb.client.TransactionInterceptor.handleInvocation(TransactionInterceptor.

            java:43)

            14:04:25,693 ERROR [stderr] (http--127.0.0.1-80-5)      at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationConte

            xt.java:181)

            14:04:25,693 ERROR [stderr] (http--127.0.0.1-80-5)      at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:1

            28)

            14:04:25,693 ERROR [stderr] (http--127.0.0.1-80-5)      at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationConte

            xt.java:181)

            14:04:25,693 ERROR [stderr] (http--127.0.0.1-80-5)      at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:136)

            14:04:25,693 ERROR [stderr] (http--127.0.0.1-80-5)      at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121)

            14:04:25,693 ERROR [stderr] (http--127.0.0.1-80-5)      at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)

            14:04:25,693 ERROR [stderr] (http--127.0.0.1-80-5)      at com.sun.proxy.$Proxy46.getGeneral(Unknown Source)

            14:04:25,693 ERROR [stderr] (http--127.0.0.1-80-5)      at org.apache.jsp.client1_jsp._jspService(client1_jsp.java:76)

            14:04:25,693 ERROR [stderr] (http--127.0.0.1-80-5)      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)

            14:04:25,693 ERROR [stderr] (http--127.0.0.1-80-5)      at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

            14:04:25,693 ERROR [stderr] (http--127.0.0.1-80-5)      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)

            14:04:25,693 ERROR [stderr] (http--127.0.0.1-80-5)      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326)

            14:04:25,693 ERROR [stderr] (http--127.0.0.1-80-5)      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253)

            14:04:25,709 ERROR [stderr] (http--127.0.0.1-80-5)      at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

            14:04:25,709 ERROR [stderr] (http--127.0.0.1-80-5)      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterCh

            ain.java:329)

            14:04:25,709 ERROR [stderr] (http--127.0.0.1-80-5)      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java

            :248)

            14:04:25,709 ERROR [stderr] (http--127.0.0.1-80-5)      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)

            14:04:25,709 ERROR [stderr] (http--127.0.0.1-80-5)      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)

            14:04:25,709 ERROR [stderr] (http--127.0.0.1-80-5)      at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAsso

            ciationValve.java:153)

            14:04:25,709 ERROR [stderr] (http--127.0.0.1-80-5)      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)

            14:04:25,709 ERROR [stderr] (http--127.0.0.1-80-5)      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

            14:04:25,709 ERROR [stderr] (http--127.0.0.1-80-5)      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

            14:04:25,709 ERROR [stderr] (http--127.0.0.1-80-5)      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)

            14:04:25,709 ERROR [stderr] (http--127.0.0.1-80-5)      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)

            14:04:25,709 ERROR [stderr] (http--127.0.0.1-80-5)      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protoc

            ol.java:671)

            14:04:25,709 ERROR [stderr] (http--127.0.0.1-80-5)      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)

            14:04:25,709 ERROR [stderr] (http--127.0.0.1-80-5)      at java.lang.Thread.run(Thread.java:724)

             

             

             

             

             

             

            This is the stack trace, I am getting in Jboss 7.1.1 I am not getting this stack trace in Jboss 4.0 .

            do you know the reason why?

            • 3. Re: Calling Empty Constructor in Jboss 7.1.1
              Sreedhar UKD Newbie

              could any one help me on this issue.

              I don't think it is  a JDK problem  because in other versions of Jboss () constructor is not calling

              It is calling only in Jboss 7

              • 4. Re: Calling Empty Constructor in Jboss 7.1.1
                Sreedhar UKD Newbie

                does anyone aware of this kind of behaviour in Jboss 7.1.1 

                 

                when we load an object it calling default constructor of that object, it is not done in Jboss 4.0.2

                 

                 

                anyone?

                • 5. Re: Calling Empty Constructor in Jboss 7.1.1
                  Stuart Douglas Master

                  If you use pass by reference this will not happen. The link below contains info on how to do this.

                   

                  https://docs.jboss.org/author/display/AS71/EJB3+subsystem+configuration+guide