7 Replies Latest reply on Sep 24, 2002 1:17 PM by Dain Sundstrom

    Exception when record not find

    Mike Newbie

      when this is no record when i call the findByPrimary key, exception will flow, why?
      how can i solve this problem?

      thanks

        • 1. Re: Exception when record not find
          Dain Sundstrom Master

          It is in the EJB specification. To fix it catch the ObjectNotFoundException.

          • 2. Re: Exception when record not find
            kyungins Newbie

            Hello. *^^*
            I Have a question!

            I confirmed that record found in Database (Oacle8i) directly.
            And I am used this CMP to WebLogic 5.1.
            But... On JBoss...
            I have got an ObjectNotFoundException. =(
            What's wrong??

            I think that JBoss3.0 have some bugs for CMP.
            But I can not found any information to CMP bugs on JBoss 3.0.

            anyboby here helped me?
            I am very tired of this trouble... =(
            please I wish to solve.


            ------------------------------------------------------------------------------------------------------------------------
            load
            ------------------------------------------------------------------------------------------------------------------------

            public java.lang.Object load(java.lang.Class type,
            java.lang.Object identity,
            java.lang.Object object)
            throws ObjectNotFoundException,
            LockNotGrantedException,
            TransactionNotInProgressException,
            PersistenceException
            Experimental
            Load an object of the specified type and given identity into a given instance of object. Once loaded the object is persistent. Calling this method with the same identity in the same transaction will return the same object. This method is equivalent to a query that returns a single object. If the identity spans on more than one field, all of the identity fields can be wrapped in a Complex object.

            Parameters:
            type - The object's type
            identity - The object's identity
            object - The object instance to be loaded into

            Throws:
            ObjectNotFoundException - No object of the given type and identity was found in persistent storage
            LockNotGrantedException - Timeout or deadlock occured attempting to acquire a lock on the object
            TransactionNotInProgressException - Method called while transaction is not in progress
            PersistenceException - An error reported by the persistence engine



            ------------------------------------------------------------------------------------------------------------------------
            ERROR MESSAGE
            ------------------------------------------------------------------------------------------------------------------------
            javax.ejb.ObjectNotFoundException: Object with primary key ejb.entity.OperatorPK@cbcc4c9d not found in storage
            at org.jboss.ejb.plugins.jaws.jdbc.JDBCFindEntityCommand.execute(JDBCFindEntityCommand.java:85)
            at org.jboss.ejb.plugins.jaws.JAWSPersistenceManager.findEntity(JAWSPersistenceManager.java:263)
            at org.jboss.ejb.plugins.CMPPersistenceManager.findEntity(CMPPersistenceManager.java:336)
            at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.findEntity(CachedConnectionInterceptor.java:301)
            at org.jboss.ejb.EntityContainer.find(EntityContainer.java:687)
            at java.lang.reflect.Method.invoke(Native Method)
            at org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityContainer.java:1116)
            at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(EntitySynchronizationInterceptor.java:209)
            at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invokeHome(CachedConnectionInterceptor.java:215)
            at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceInterceptor.java:88)
            at org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLockInterceptor.java:79)
            at org.jboss.ejb.plugins.EntityCreationInterceptor.invokeHome(EntityCreationInterceptor.java:44)
            at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:98)
            at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:176)
            at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:52)
            at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:104)
            at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:118)
            at org.jboss.ejb.EntityContainer.invokeHome(EntityContainer.java:487)
            at org.jboss.ejb.Container.invoke(Container.java:726)
            at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:1055)
            at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:491)
            at org.jboss.invocation.local.LocalInvoker.invoke(LocalInvoker.java:98)
            at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:102)
            at org.jboss.proxy.TransactionInterceptor.invoke(TransactionInterceptor.java:73)
            at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:76)
            at org.jboss.proxy.ejb.HomeInterceptor.invoke(HomeInterceptor.java:198)
            at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:76)
            at $Proxy46.findByPrimaryKey(Unknown Source)
            at org.apache.jsp.entity$jsp._jspService(entity$jsp.java:145)
            at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
            at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:201)
            at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:381)
            at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
            at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
            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:2347)
            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.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1027)
            at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125)
            at java.lang.Thread.run(Thread.java:479)
            ------------------------------------------------------------------------------------------------------------------------

            • 3. Re: Exception when record not find
              Dain Sundstrom Master

              Ok a couple of points here.

              Are you sure your code is connecting to Oracle and not the default (builtin) HypersonicSQL database?

              Whay are you using CMP 1.1? I suggest you use CMP 2.0, but if you choose not to I suggest you switch to using an EJB 2.0 depoloment descriptor with cmp 1.1 backward compatability mode.

              Right now you are using Jaws, which is our old CMP 1.1 only persistence engine and is no longer supported. This is why I suggest changing to an EJB 2.0 dd.

              Are you using JBoss 3.0.2? If not upgrade.

              You are using a custom pk. Custom primary keys are difficult to correctly code and are usually the source many bugs. Do you really need it? If so, double and tripple check the code. Pay particular attention to the equals and hashCode methods.

              • 4. Re: Exception when record not find
                Mike Newbie

                I am using Mysql and CMP2.0, it works fine until now

                • 5. Re: Exception when record not find
                  Dain Sundstrom Master

                  My reply was to the other guy. Anyway, as I said before, catch the ObjectNotFoundException.

                  • 6. Re: Exception when record not find
                    kyungins Newbie

                    I can't use TRY/CATCH syntax to ObjectNotFoundException because there is data in database.
                    I'd like to catch the root cause. =(
                    Please Help me...

                    -------------------------------------------------------------------------
                    I tried to get the data using by 4 way.
                    -------------------------------------------------------------------------
                    1) DriveManager

                    like this...

                    Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@999.999.99.99:1521:ORCL","aaa","bbb");

                    RESULT => Succeeded.

                    2) direct sql

                    like this...

                    select * from Operator where opid="ccc";

                    RESULT => Succeeded.

                    3) Session Bean (oracle connection pool)

                    like this...

                    ctx = new javax.naming.InitialContext(ctxProps);
                    String dbName = "java:/OracleDS";
                    DataSource ds = (DataSource) ctx.lookup(dbName);

                    RESULT => Succeeded.

                    4) Entity Bean (oracle connection pool)

                    like this...

                    Object objref = ctx.lookup("Operator");
                    OperatorHome oHome = (OperatorHome) PortableRemoteObject.narrow(objref, OperatorHome.class);

                    RESULT => Failed.

                    -------------------------------------------------------------------------
                    And I tried to next versions.
                    -------------------------------------------------------------------------
                    jboss-3.0.1RC1_tomcat-4.0.4
                    jboss-3.0.0_tomcat-4.0.3
                    jboss-3.0.0 (with jetty)
                    jboss-3.0.2 (with jetty)


                    -------------------------------------------------------------------------
                    OperatorPK.java
                    -------------------------------------------------------------------------
                    package aaaaa;
                    import java.io.Serializable;

                    public class OperatorPK implements Serializable
                    {
                    public String opid;

                    public OperatorPK() {}

                    public int hashCode() {

                    return (opid.hashCode());

                    }

                    public boolean equals(Object that) {

                    if (!(that instanceof OperatorPK))
                    return false;

                    OperatorPK tmp = (OperatorPK)that;
                    return (this.opid.equals(tmp.opid));

                    }
                    }

                    -------------------------------------------------------------------------
                    Deploy message (Successful)
                    -------------------------------------------------------------------------
                    14:31:16,577 INFO [MainDeployer] Starting deployment of package: file:/C:/java/
                    jboss-3.0.0_tomcat-4.0.3/server/default/deploy/PGCMP_G3.jar
                    14:31:16,764 INFO [EjbModule] Creating
                    14:31:16,780 INFO [EjbModule] Deploying ZIPCode
                    14:31:17,171 INFO [EjbModule] Deploying PGKey
                    14:31:17,186 INFO [EjbModule] Deploying Operator
                    14:31:17,202 INFO [EjbModule] Deploying AccessList
                    14:31:17,202 INFO [EjbModule] Deploying OPPage
                    14:31:17,218 INFO [EjbModule] Deploying GAccessList
                    14:31:17,718 INFO [JDBCInitCommand] Created table 'OPPage' successfully.
                    14:31:17,796 INFO [JDBCInitCommand] Created table 'AccessList' successfully.
                    14:31:17,811 INFO [JDBCInitCommand] Created table 'Operator' successfully.
                    14:31:17,827 INFO [JDBCInitCommand] Created table 'PGKey' successfully.
                    14:31:17,843 INFO [JDBCInitCommand] Created table 'GAccessList' successfully.
                    14:31:17,858 INFO [JDBCInitCommand] Created table 'ZIPCode' successfully.
                    14:31:17,858 INFO [EjbModule] Created
                    14:31:17,858 INFO [EjbModule] Starting
                    14:31:18,124 INFO [EjbModule] Started
                    14:31:18,124 INFO [MainDeployer] Successfully completed deployment of package:
                    file:/C:/java/jboss-3.0.0_tomcat-4.0.3/server/default/deploy/PGCMP_G3.jar

                    • 7. Re: Exception when record not find
                      Dain Sundstrom Master

                      You can't look up the home interface? Did you give it an exact JNDI binding in the jboss.xml file?

                      On another issue, why are you using a custom pk class to wrap a single String value? You should implement toString for easier debugging.