0 Replies Latest reply on Jul 19, 2002 6:04 AM by qjafcunuas

    Can't lookup EntityBean in servlet.init();

    qjafcunuas

      Hi,
      I'm using JBoss2.4.6 on Debian.
      In my servlet.init() method, i call "lookup" to get the home interface of 4 EntityBeans i'will use.

      For 3 of them, it's ok, but not for one of them.

      Nevertheless, why i call "lookup" for this Entity Bean in a Session Bean, it's ok, and after that, the servlet find the Entity Bean !

      Can somebody help me ?
      thanks a lot

      Bruno.

      Here is the home interface of the Entity Bean
      ---------------------------------------------------------
      package XXX;

      import java.rmi.RemoteException;
      import javax.ejb.EJBHome;
      import javax.ejb.CreateException;
      import javax.ejb.FinderException;
      import java.util.Enumeration;

      public interface MyEntityBeanHome extends EJBHome {
      public MyEntityBean create(Integer Key, Date date, int i)
      throws CreateException, RemoteException;

      public MyEntityBean findByPrimaryKey(Integer pk)
      throws FinderException, RemoteException;

      public Enumeration findByLook(int p_iId)
      throws FinderException, RemoteException;
      }
      ---------------------------------------------------------
      Here is the remote Interface of the Entity Bean :
      ---------------------------------------------------------
      package XXX;

      import java.rmi.RemoteException;
      import javax.ejb.EJBObject;

      public interface MyEntityBean extends EJBObject {
      public void setDate(Date date) throws RemoteException;
      public void setLook(int i) throws RemoteException;
      public Date getDate() throws RemoteException;
      public int getLook() throws RemoteException;
      }
      ---------------------------------------------------------
      Here is the bean :
      ---------------------------------------------------------
      package XXX.ejb;

      import javax.ejb.EntityContext;
      import javax.ejb.CreateException;
      import javax.ejb.EJBException;
      import javax.ejb.RemoveException;
      import javax.ejb.FinderException;
      import javax.ejb.EntityBean;
      import java.rmi.RemoteException;
      import java.util.Vector;
      import java.util.Enumeration;
      import java.util.Hashtable;

      public class MyEntityBeanBean implements EntityBean {

      private EntityContext m_oContext;
      private Integer m_oKey;
      private Date m_dDate;
      private int m_iLook;

      public void setEntityContext(EntityContext p_oContext) {
      m_oContext = p_oContext;
      }

      public void unsetEntityContext() {
      m_oContext = null;
      }

      public void setDate(Date date) throws RemoteException {
      m_dDate = date;
      }

      public void getDate() throws RemoteException {
      return m_dDate;
      }

      public void setLook(int i) throws RemoteException {
      m_iLook = i;
      }

      public int getLook() throws RemoteException {
      return m_iLook;
      }

      public Integer ejbCreate(Integer Key, Date date, int i)
      throws CreateException, RemoteException {
      m_dDate = date;
      m_iLook = i;
      m_oKey = key;
      // Data save in DB
      return m_oKey;
      }

      public void ejbPostCreate(Integer Key, Date date, int i)
      throws CreateException, RemoteException {
      // Nothing to do
      }

      public void ejbLoad() {
      // Load Data from DB
      }


      public void ejbStore() {
      // Store Data in DB
      }

      public void ejbRemove() throws RemoteException, RemoveException {
      // Remove Data from DB
      }

      public void ejbActivate() {
      m_oKey = (Integer) m_oContext.getPrimaryKey();
      }

      public void ejbPassivate() {
      m_oKey = null;
      }

      public Integer ejbFindByPrimaryKey(Integer p_oKey)
      throws RemoteException, FinderException {
      // Search in DB
      return oKey;
      }

      public Enumeration ejbFindByLook(int p_iId)
      throws RemoteException, FinderException {
      // Search in DB
      return Vector.elements();
      }
      }
      ---------------------------------------------------------
      Here is my ejb-jar.xml for the Entity Bean :
      ---------------------------------------------------------

      ...
      <ejb-name>MyEntityBeanName</ejb-name>
      XXX.MyEntityBeanHome
      XXX.MyEntityBean
      <ejb-class>XXX.MyEntityBeanBean</ejb-class>
      <persistence-type>Bean</persistence-type>
      <prim-key-class>Integer</prim-key-class>
      True
      <resource-ref>
      <res-ref-name>jdbc/myDB</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>

      /../
      <container-transaction>

      <ejb-name>MyEntityBeanName</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Supports</trans-attribute>
      </container-transaction>
      <container-transaction>

      <ejb-name>MyEntityBeanName</ejb-name>
      <method-name>create</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>

      <ejb-name>MyEntityBeanName</ejb-name>
      <method-name>remove</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>

      <ejb-name>MyEntityBeanName</ejb-name>
      <method-name>setDate</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>

      <ejb-name>MyEntityBeanName</ejb-name>
      <method-name>setLook</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      ---------------------------------------------------------
      Here is my jboss.xml for the Entity Bean :
      ---------------------------------------------------------

      <ejb-name>MyEntityBeanName</ejb-name>
      <jndi-name>MyEntityBeanJndi</jndi-name>

      <res-ref-name>jdbc/myDB</res-ref-name>
      <jndi-name>ems:Services/JdbcServiceManager/deployed/jdbc_1</jndi-name>


      ---------------------------------------------------------
      Here is my web.xml for the Entity Bean :
      ---------------------------------------------------------
      <ejb-ref>
      ...
      <ejb-ref-name>ejb/MyEntityBean</ejb-ref-name>
      <ejb-ref-type>Entity</ejb-ref-type>
      XXX.MyEntityBeanHome
      XXX.MyEntityBean
      <ejb-link>MyEntityBeanJndi</ejb-link>
      </ejb-ref>

      ---------------------------------------------------------
      When the servlet.init() method is called, i've got this exception :
      [10:21:56,355,Engine] myServlet: init
      [10:21:56,548,Engine] StandardWrapperValve[myServlet]: Allocate exception for servlet myServlet
      javax.servlet.ServletException: Servlet.init() for servlet myServlet threw exception
      at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:935)
      at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:653)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2343)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.ajp.tomcat4.Ajp13Processor.process(Ajp13Processor.java:429)
      at org.apache.ajp.tomcat4.Ajp13Processor.run(Ajp13Processor.java:495)
      at java.lang.Thread.run(Thread.java:536)
      [10:21:56,688,Engine] ----- Root Cause -----
      java.lang.NoSuchMethodError: create
      at $Proxy3013.(Unknown Source)
      at sun.reflect.GeneratedSerializationConstructorAccessor4496.newInstance(Unknown Source)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
      at java.io.ObjectStreamClass.newInstance(ObjectStreamClass.java:759)
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1621)
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1264)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:322)
      at java.rmi.MarshalledObject.get(MarshalledObject.java:135)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:439)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:419)
      at javax.naming.InitialContext.lookup(InitialContext.java:347)
      at XXX.myServlet.init(myServlet.java:59)
      at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:916)
      at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:653)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2343)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
      at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
      at org.apache.ajp.tomcat4.Ajp13Processor.process(Ajp13Processor.java:429)
      at org.apache.ajp.tomcat4.Ajp13Processor.run(Ajp13Processor.java:495)
      at java.lang.Thread.run(Thread.java:536)