I am fairly new to EJBs Is it possible to use EJBs to retrieve data from a database (eg db2) when you don't have the primary key. From what I can see, to create a remote interface you always need to have the primary key. I want to access the database using a non-primary key and return 2 or more results that the session bean can handle and manipulate. Is it possible to do this and if so, could you tell me how. I would really appreciate some help here Thanks Kathy
You can write finders for anything. The findByPrimaryKey is required, but you can also write findByCity(String city) and findAllWetStinkyDogs() or whatever. They just have to be named "find<whatever>". Finders may return a single bean or a Collection of them. You just define what you want in the home interface and provide an appropriate implementation. If you are using CMP (Container Managed Persistence), this means you supply the appropriate EJB-QL in your deployment descriptor. If you are writing BMP (Bean managed), then you author a method called "ejbFind<whatever>" that takes the same arguments as the one in your home. The only difference is that this one returns a PK or a Collection of PK objects. So that's the two-cent overview. Grab a good EJB book - I like the one by Richard Monson-Haefel from OReilly. Ed Rowman's is pretty good too, and you can download a copy from theserverside.com.
You MUST define a find by primary key, but you can also define custom finders. The findByPrimaryKey should only ever return one instance (that is why it's called find by primary key -- in relational datbase terminology there must ALWAYS be some combination of columns that uniquely identifies a row). However a custom finder may return a collection of objects, since it searches on something other than the primary key. Again READ A GOOD EJB BOOK. It will help. Kyle