Hi Group:

I am having a tough time making a custom finder work for me. Here is my
setup: Windows NT, JBoss-2.2.2_Tomcat-3.2.2, JDK 1.3, Oracle 8i. When I try
to access my bean from the client, following is the error message which I
get:

javax.ejb.FinderException: Find failed

        at
sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteC
all.java:245)

        at
sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:220)

        at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:122)

        at
org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker_Stub.invokeHome(Unkno
wn Source)

        at
org.jboss.ejb.plugins.jrmp.interfaces.HomeProxy.invoke(HomeProxy.java:248)

        at $Proxy0.findByUsernamePassword(Unknown Source)

        at
com.acs.ejb.JamalSecurityClient.<init>(JamalSecurityClient.java:26)

        at com.acs.ejb.JamalSecurityClient.main(JamalSecurityClient.java:38)



(Note: I can find the same row from the database using the
findByPrimaryKey(new Long(4)) without any problem.)

I have defined a simple CMP entity ejb to represent a table AR_SECURITY with
3 columns: SECURITY_ID, USERNAME, PASSWORD.

I am trying to find an istance of my ejb by supplying a username and
password. So, I defined a method called findByUsernamePassword(String
username, String password) in the home interface. I added the query into
jaws.xml. Here are the files for the jamalSecurity CMP ejb:


1- remote interface: JamalSecurity.java

package com.acs.ejb;

import java.rmi.RemoteException;
import javax.ejb.EJBObject;
import javax.ejb.FinderException;
import javax.ejb.EJBException;
public interface JamalSecurity extends EJBObject {
        public Long getSecurity_id() throws RemoteException;
        public void setSecurity_id(Long p) throws RemoteException;
        public String getUsername() throws RemoteException;
        public void setUsername(String p) throws RemoteException;
        public String getPassword() throws RemoteException;
        public void setPassword(String p) throws RemoteException;
}


2- home interface: JamalSecurityHome.java

package com.acs.ejb;

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

public interface JamalSecurityHome extends EJBHome {
        public com.acs.ejb.JamalSecurity create(String password__p,Long
security_id__p,String username__p) throws CreateException, EJBException,
RemoteException;
        public com.acs.ejb.JamalSecurity findByPrimaryKey(Long pk) throws
FinderException, RemoteException;
        public Long findByUsernamePassword(String username, String password)
throws FinderException, RemoteException;
}

3- Bean Implementation: JamalSecurityBean.java
package com.acs.ejb;

import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EntityBean;
import javax.ejb.RemoveException;
import javax.ejb.EJBException;
import javax.ejb.EntityContext;
import javax.ejb.FinderException;
import javax.sql.DataSource;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.sql.*;

public class JamalSecurityBean implements EntityBean {

        public Long getSecurity_id() throws RemoteException {
                return security_id_;
        }
        public void setSecurity_id(Long p) throws RemoteException {
                security_id_ = p;
        }
        public String getUsername() throws RemoteException {
                return username_;
        }
        public void setUsername(String p) throws RemoteException {
                username_ = p;
        }
        public String getPassword() throws RemoteException {
                return password_;
        }
        public void setPassword(String p) throws RemoteException {
                password_ = p;
        }
        public java.lang.Long ejbCreate(String password__p,Long
security_id__p,String username__p) throws CreateException, EJBException,
RemoteException {
                password_ = password__p;                
                security_id_ = security_id__p;          
                username_ = username__p;                
                return null;
        }
        public void ejbLoad() {
                // To do here
        }
        public void ejbStore() {
                // To do here
        }
        public void ejbRemove() {
                // To do here
        }
        public void ejbPostCreate(String password__p,Long
security_id__p,String username__p) {
                // To do here
        }
        public void ejbPassivate() {
                // To do here
        }
        public void ejbActivate() {
                // To do here
        }
        public void setEntityContext(EntityContext context) {
                this.context = context;
        }
        public void unsetEntityContext() throws EJBException {
                this.context = null;
        }
        public Long ejbFindByPrimaryKey(Long pk) throws FinderException,
RemoteException {
                security_id_ = pk;              
                return pk;
        }
        
        public EntityContext context;
        public String password_;
        public Long security_id_;
        public String username_;
        protected java.sql.Connection connection_0_;
}

4- ejb-jar.xml 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise
JavaBeans 1.1//EN' 'http://java.sun.com/j2ee/dtds/ejb-jar_1_1.dtd'>
<ejb-jar>
<description></description>
<display-name>JamalSecurity</display-name>
<enterprise-beans>
<entity>
    <ejb-name>JamalSecurity</ejb-name>
    <home>com.acs.ejb.JamalSecurityHome</home>
    <remote>com.acs.ejb.JamalSecurity</remote>
    <ejb-class>com.acs.ejb.JamalSecurityBean</ejb-class>
    <persistence-type>Container</persistence-type>
    <prim-key-class>java.lang.Long</prim-key-class>
    <reentrant>True</reentrant>
    <cmp-field>
      <field-name>password_</field-name>
    </cmp-field>
    <cmp-field>
      <field-name>security_id_</field-name>
    </cmp-field>
    <cmp-field>
      <field-name>username_</field-name>
    </cmp-field>
    <primkey-field>security_id_</primkey-field>
  
    <resource-ref>
      <res-ref-name>jdbc/OraclePool</res-ref-name>
      <resource-name>OraclePool</resource-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
    </resource-ref>
  </entity>
</enterprise-beans>
<assembly-descriptor>

    <container-transaction>
      <method>
        <ejb-name>JamalSecurity</ejb-name>
        <method-intf>Remote</method-intf>
        <method-name>getSecurity_id</method-name>
        <method-params />
      </method>
      <trans-attribute>Required</trans-attribute>
    </container-transaction>
    <container-transaction>
      <method>
        <ejb-name>JamalSecurity</ejb-name>
        <method-intf>Remote</method-intf>
        <method-name>setSecurity_id</method-name>
        <method-params>
          <method-param>java.lang.String</method-param>
        </method-params>
      </method>
      <trans-attribute>Required</trans-attribute>
    </container-transaction>
    <container-transaction>
      <method>
        <ejb-name>JamalSecurity</ejb-name>
        <method-intf>Remote</method-intf>
        <method-name>getUsername</method-name>
        <method-params />
      </method>
      <trans-attribute>Required</trans-attribute>
    </container-transaction>
    <container-transaction>
      <method>
        <ejb-name>JamalSecurity</ejb-name>
        <method-intf>Remote</method-intf>
        <method-name>setUsername</method-name>
        <method-params>
          <method-param>java.lang.String</method-param>
        </method-params>
      </method>
      <trans-attribute>Required</trans-attribute>
    </container-transaction>
    <container-transaction>
      <method>
        <ejb-name>JamalSecurity</ejb-name>
        <method-intf>Remote</method-intf>
        <method-name>getPassword</method-name>
        <method-params />
      </method>
      <trans-attribute>Required</trans-attribute>
    </container-transaction>
    <container-transaction>
      <method>
        <ejb-name>JamalSecurity</ejb-name>
        <method-intf>Remote</method-intf>
        <method-name>setPassword</method-name>
        <method-params>
          <method-param>java.lang.String</method-param>
        </method-params>
      </method>
      <trans-attribute>Required</trans-attribute>
    </container-transaction>
    <container-transaction>
      <method>
        <ejb-name>JamalSecurity</ejb-name>
        <method-intf>Home</method-intf>
        <method-name>FindByPrimaryKey</method-name>
        <method-params>
          <method-param>java.lang.Long</method-param>
        </method-params>
      </method>
      <trans-attribute>Required</trans-attribute>
    </container-transaction>
                
</assembly-descriptor>
</ejb-jar>


5- jaws.xml

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

<jaws>
   <enterprise-beans>
     <entity>
       <ejb-name>JamalSecurity</ejb-name>
       <table-name>AR_SECURITY</table-name>
       <create-table>false</create-table>
       <cmp-field>
         <field-name>security_id_</field-name>
         <column-name>SECURITY_ID</column-name>
       </cmp-field>
       <cmp-field>
         <field-name>username_</field-name>
         <column-name>USERNAME</column-name>
       </cmp-field>
       <cmp-field>
         <field-name>password_</field-name>
         <column-name>PASSWORD</column-name>
       </cmp-field>
                         
       <finder>
             <name>findByUsernamePassword</name>
        <query>username_ = {0} AND password_ = {1}</query>
        <order></order>
       </finder>
                         
            
     </entity>
   </enterprise-beans>
         
   <datasource>OraclePool</datasource> 
   <type-mapping>Oracle8</type-mapping> 
         
 </jaws>
 
6- jboss.xml

<?xml version="1.0" encoding="UTF-8"?>
<jboss>
  <enterprise-beans>
    <entity>
      
        <ejb-name>JamalSecurity</ejb-name>
        <jndi-name>jamalsecurity/JamalSecurity</jndi-name>
                  
        <resource-ref>
                <resource-name>OraclePool</resource-name>
                <res-ref-name>jdbc/OraclePool</res-ref-name>

        </resource-ref>
        
     </entity>
  </enterprise-beans>
        
<resource-managers>
        
        <resource-manager>
                <res-name>OraclePool</res-name>
                <res-jndi-name>java:/OraclePool</res-jndi-name>

        </resource-manager>
                
</resource-managers>

</jboss>


7- My client code to access the EJB: JamalSecurityClient.java:

package com.acs.ejb;

import java.rmi.RemoteException;
import java.util.*;
import javax.naming.*;
import javax.naming.NamingException;
import javax.ejb.EJBException;
import javax.ejb.FinderException;
import javax.rmi.PortableRemoteObject;

import com.acs.ejb.*;

public class JamalSecurityClient {

        public JamalSecurityClient() {
                try {

                Context ic = getJBossInitialContext();
                JamalSecurityHome home = (JamalSecurityHome)ic.lookup(
"jamalsecurity/JamalSecurity" );

                JamalSecurity remoteInt =
home.findByUsernamePassword("jack","village");
                

                
                System.out.println("\n      ID is: " +
remoteInt.getSecurity_id());
                System.out.println("Username is: " + remoteInt.getUsername()
+ "\n");
                
                } catch (Exception except) {
                except.printStackTrace();
                }
        }
        public static void main(String[] argv) {
                JamalSecurityClient client = new JamalSecurityClient();
        }
        
        public static Context getJBossInitialContext() 
                          throws javax.naming.NamingException {
        Properties env = new Properties();
    env.setProperty("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
    env.setProperty("java.naming.provider.url",  "localhost:1099");
    env.setProperty("java.naming.factory.url.pkgs",  "org.jboss.naming");
return new javax.naming.InitialContext(env);
  }
}


I thank you in advance for your help.

Regards,
Jamal.



_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to