You CANNOT use java.lang.String as your PK class unless:
The pk is a single field.
The field is of a VARCHAR or CHAR type or similar.
If the underlaying DB has a composite pk(the pk is more than a single
field), then you must create your OWN pk class.
I suggest you look around at www.theserverside.com for a .pdf file
that's called Mastering Enterprise JavaBeans.
Read it. It has examples, most developed on top of Weblogic 6.x.
An example of a PK(composite) class follows:
public class AlbumTrackBeanPK implements Serializable
{
public long albumId;
public long trackId;
public boolean equals(Object obj)
{
AlbumTrackBeanPK pkObj=(AlbumTrackBeanPK)obj;
return (albumId==(pkObj.albumId) && trackId==(pkObj.trackId) );
}
public int hashCode()
{
try
{
long crcKey = -1;
java.io.ByteArrayOutputStream bos = new
java.io.ByteArrayOutputStream();
java.io.ObjectOutputStream oos = new
java.io.ObjectOutputStream(bos);
oos.writeObject(this);
oos.flush();
java.util.zip.Adler32 adl32 = new java.util.zip.Adler32();
adl32.update(bos.toByteArray());
crcKey = adl32.getValue();
return (int)(crcKey ^ (crcKey >> 32));
} catch (java.io.IOException ioEx)
{
return -1;
}
}
}
It was generated with Pramati Studio 3.0
HTH,
Juan Pablo Lorandi
Chief Software Architect
Code Foundry Ltd.
[EMAIL PROTECTED]
Barberstown, Straffan, Co. Kildare, Ireland.
Tel: +353-1-6012050 Fax: +353-1-6012051
Mobile: +353-86-2157900
www.codefoundry.com
> -----Original Message-----
> From: A mailing list for Enterprise JavaBeans development
> [mailto:[EMAIL PROTECTED]] On Behalf Of phani
> Sent: Wednesday, May 24, 2000 11:39 AM
> To: [EMAIL PROTECTED]
> Subject: Re: Need some examples
>
>
> hi,
> I created another method ejbFindByUserName(String aKey){}
> but no luck... it is throwing a jit error... and retruns null
> only... Thanks for help phani
>
> ----- Original Message -----
> From: <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Monday, June 24, 2002 3:18 PM
> Subject: Re: Need some examples
>
>
> >
> > Create a new find by method:
> > findByUsername(String username)
> > The find by primaryKey is used by the container I think
> >
> > > from: phani <[EMAIL PROTECTED]>
> > > date: Mon, 24 Jun 2002 09:57:47
> > > to: [EMAIL PROTECTED]
> > > subject: Re: Need some examples
> > >
> > > Hi,
> > > I got the primary key class concept....
> > > If i have written a primary key class then i will use
> that class
> > > or i
> can
> > > use defalt java.lang.string class as primary key class ... right?
> > >
> > > Now my problem is i have a login table with two fields user_id and
> password.
> > > I am using Oracle8i DB and i am using BMP.
> > >
> > > I want to get the password from client by entering user_id.
> > >
> > > I coded Entity.java(Remote) EntityHome.java(Home) and
> EnitytEJB.java(Bean)
> > > and EnityClient.java (Client)
> > >
> > > But Client returning null value...
> > >
> > >
> > > -----------
> > > Entity.java
> > >
> > > import java.rmi.RemoteException;
> > > import javax.ejb.EJBObject;
> > > public interface Entity extends EJBObject {
> > > String getPassword()throws RemoteException;
> > > }
> > > ----------------
> > > EntityHome.java
> > >
> > > import java.rmi.RemoteException;
> > >
> > > import javax.ejb.CreateException;
> > > import javax.ejb.EJBHome;
> > > import javax.ejb.FinderException;
> > > public interface EntityHome extends EJBHome {
> > > public Entity findByPrimaryKey(String aKey)
> > > throws RemoteException, FinderException;
> > > }
> > > -----------
> > > EntityEJB.java
> > >
> > > import javax.ejb.CreateException;
> > > import javax.ejb.EntityBean;
> > > import javax.ejb.EntityContext;
> > > import javax.ejb.FinderException;
> > > import java.sql.*;
> > >
> > > public class EntityEJB implements EntityBean {
> > >
> > > /**
> > > * No argument constructor required by container.
> > > */
> > > private EntityContext ctx;
> > > public String password;
> > > public EntityEJB() {
> > > }
> > >
> > > /**
> > > * Reference EJB specification 1.1 section 9.2.5
> > > */
> > > public String ejbFindByPrimaryKey(String aKey)
> > >
> > > Connection con=null;
> > > PreparedStatement ps=null;
> > > ResultSet rs=null;
> > > String password=null;
> > > try{
> > > Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
> > >
> > >
> con=DriverManager.getConnection("jdbc:odbc:vqi","system","manager");
> > > }catch(Exception e){System.out.println(e);}
> > > try{
> > > ps=con.prepareStatement("select password from
> system.login
> > > where user_id=?");
> > > ps.setString(1,aKey.trim());
> > > rs=ps.executeQuery();
> > > while(rs.next())
> > > {
> > > password=rs.getString("password");
> > > System.out.println(password);//it is printing the password
> > > }
> > > con.close();
> > > }catch(Exception e){System.out.println(e);}
> > > return aKey;
> > > }
> > >
> > > /* Methods required for EntityBean interface. EJB 1.1 section
> > > 9.4 */
> > >
> > > /**
> > > * @see javax.ejb.EntityBean#ejbActivate()
> > > */
> > > public void setEntityContext(EntityContext context){
> > > this.ctx=context;
> > > }
> > >
> > > /**
> > > * @see javax.ejb.EntityBean#unsetEntityContext()
> > > */
> > > public void unsetEntityContext(){
> > >
> > > }
> > >
> > > /**
> > > * @see javax.ejb.EntityBean#ejbActivate()
> > > */
> > > public void ejbActivate() {
> > > }
> > >
> > > /**
> > > * @see javax.ejb.EntityBean#ejbPassivate()
> > > */
> > > public void ejbPassivate() {
> > > }
> > >
> > > /**
> > > * @see javax.ejb.EntityBean#ejbLoad()
> > > */
> > > public void ejbLoad() {
> > > }
> > >
> > > /**
> > > * @see javax.ejb.EntityBean#ejbStore()
> > > */
> > > public void ejbStore() {
> > > }
> > >
> > > /**
> > > * @see javax.ejb.EntityBean#ejbRemove()
> > > */
> > > public void ejbRemove() {
> > > }
> > >
> > > public java.lang.String getPassword() {
> > > System.out.println(password);
> > > return password;
> > > }
> > >
> > > }
> > > ----------
> > > EnityClient
> > > import javax.naming.*;
> > > import java.util.*;
> > > public class EntityClient
> > > {
> > > public static void main(String args[])
> > > throws Exception
> > > {try{
> > > System.out.println(" Please wait....");
> > > Properties p=new Properties();
> > >
> > >
> p.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.T3Initial
> ContextFactory
> > > ");
> > > p.put(Context.PROVIDER_URL,"t3://localhost:7001");
> > > Context ctx=new InitialContext(p);
> > > EntityHome h=(EntityHome)ctx.lookup("bmpBean");
> > > Entity robj=h.findByPrimaryKey("phani");
> > > System.out.println(robj.getPassword());
> > > }catch(Exception e){System.out.println(e);}
> > > } // main
> > > } // end of EmpClient
> > >
> > > Can some one tell me where i went wrong?
> > > I have major doubt regarding to my findbyprimarykey() method
> overiding.....
> > > what i have done was right?
> > >
> > > Can some one point me in right direction?
> > >
> > > Thanks in advance
> > > phani
> > >
> > > ----- Original Message -----
> > > From: Ashwani Kalra <[EMAIL PROTECTED]>
> > > To: <[EMAIL PROTECTED]>
> > > Sent: Monday, June 24, 2002 1:42 PM
> > > Subject: Re: Need some examples
> > >
> > >
> > > > You need primary key class when there are more than one
> field(composite
> > > > key). Check your deployment descriptor. For the
> <prim-key-class>
> element.
> > > > ----- Original Message -----
> > > > From: "phani" <[EMAIL PROTECTED]>
> > > > To: <[EMAIL PROTECTED]>
> > > > Sent: Monday, June 24, 2002 1:35 PM
> > > > Subject: Re: Need some examples
> > > >
> > > >
> > > > > Hi vellosa,
> > > > > Thanks for the info.
> > > > >
> > > > > I checked the sample dir. But I have read that the
> entity bean
> > > > > must
> > > > require
> > > > > an Primary key class.
> > > > > But i don't find any primary key class in the
> > > > > samples/examples/ejb/basic/beanManaged
> > > > > I have account.java(Remote) accountHome.java(Home)
> accountBean.java(EJB)
> > > > and
> > > > > client.java but where is Primary Key class.
> > > > >
> > > > > Thanks for the help
> > > > > phani
> > > > >
> > > > > ----- Original Message -----
> > > > > From: <[EMAIL PROTECTED]>
> > > > > To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
> > > > > Sent: Monday, June 24, 2002 1:24 PM
> > > > > Subject: Re: Need some examples
> > > > >
> > > > >
> > > > > > Hi Phani,
> > > > > >
> > > > > > I am using WebLogic 6.1 and there in the directory:
> > > > > >
> > > > > > C:\bea\wlserver6.1\samples\examples
> > > > > >
> > > > > > I have a whole set of examples for everything you
> could ever
> > > > > > need
> to
> > > do
> > > > on
> > > > > WebLogic, well quite a bit anyway. There are examples
> of EJB 1.1
> > > > > and
> 2.0
> > > > > BMP, CMP and even Message Driven Beans. I'm sure you must have
> something
> > > > > similar under your 6.0 instalation?
> > > > > >
> > > > > > Regards
> > > > > > IV
> > > > > >
> > > > > >
> > > > > >
> > > > > > > from: phani <[EMAIL PROTECTED]>
> > > > > > > date: Mon, 24 Jun 2002 08:41:58
> > > > > > > to: [EMAIL PROTECTED]
> > > > > > > subject: Re: Need some examples
> > > > > > >
> > > > > > > Hi,
> > > > > > > I am new bie to ejb and i am messed with
> deploying entity
> beans on
> > > > > WL6.0
> > > > > > >
> > > > > > > I need some basic examples for entity beans
> (both cmp and
> bmp)
> > > > > specific to weblogic 6.0 so that i can deploy and run without
> > > > > any modifications.
> > > > > > >
> > > > > > > Are there any examples available with WL6.0 specific xml
> > > > > > > files? I searched the web but no luck.
> > > > > > >
> > > > > > > Thanks for any help
> > > > > > > phani
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > >
> > >
> http://www.amazon.co.uk/exec/obidos/redirect-home?tag=vellosco
> uk-21&placemen
> > > > > t=home_multi.gif&site=amazon
> > > > >
> > > > >
> > > >
> > >
> ==============================================================
> =============
> > > > > To unsubscribe, send email to [EMAIL PROTECTED]
> and include
> > > > > in
> the
> > > > body
> > > > > of the message "signoff EJB-INTEREST". For general
> help, send
> > > > > email
> to
> > > > > [EMAIL PROTECTED] and include in the body of the message
> > > > > "help".
> > > > >
> > > >
> > > >
> > >
> ==============================================================
> =============
> > > > To unsubscribe, send email to [EMAIL PROTECTED] and
> include in
> > > > the
> > > body
> > > > of the message "signoff EJB-INTEREST". For general help, send
> > > > email
> to
> > > > [EMAIL PROTECTED] and include in the body of the message
> > > > "help".
> > >
> > >
> ==============================================================
> =============
> > > To unsubscribe, send email to [EMAIL PROTECTED] and
> include in
> > > the
> body
> > > of the message "signoff EJB-INTEREST". For general help,
> send email
> > > to [EMAIL PROTECTED] and include in the body of the message
> > > "help".
> > >
> >
> >
> >
> >
> http://www.amazon.co.uk/exec/obidos/redirect-home?tag=vellosco
uk-21&placemen
t=home_multi.gif&site=amazon
========================================================================
===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body of the message "signoff EJB-INTEREST". For general help, send
email to [EMAIL PROTECTED] and include in the body of the message
"help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".