• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

Entity EJB accessing Database without primary key

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey ,
we cannot find a unique entity bean instance without defining a primarykey.
If we do not have a findbyprimarykey in my home Interface the creation of jar will fail.
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Yeah, but how did the squirrel get in there? Was it because of the tiny ad?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic