Entity Bean - findbyPrimaryKey()


EJB design: Entity Bean - findbyPrimaryKey()

  1. Entity Bean - findbyPrimaryKey() (5 messages)

    If the primary key is a composite primary key we are not able to access the values. Since, if we use findbyprimarykey(for a table having composite primary key) it retrieves only the value of the first record.

    Threaded Messages (5)

  2. Entity Bean - findbyPrimaryKey()[ Go to top ]


    If a table is having composite key,in CMP u have to write PrimaryKey class.I think this helps u


  3. Entity Bean - findbyPrimaryKey()[ Go to top ]

    I have used a primary class. The problem is - for example if i have 5 records. The home object refers to 5 records but it retrieves only the first record.
  4. Entity Bean - findbyPrimaryKey()[ Go to top ]

     I'm not sure i understood ur question.
     what do u mean by refer to 5 records??
     findByPrimaryKey method retrieves only 1 record not an enumeration?

  5. Hi ,

    the consept of entity bean is thet it represents ONE row in the database.
    a primary key represents a unique value in a record.
    so,if u use findbyPrimaryKey it always returns u only one entity bean means one record.
    if u need to retrieve more than one record, u have to use other finder methods.

    i think it solves ur problem.

  6. Entity Bean - findbyPrimaryKey()[ Go to top ]

       Hope this article will be of use to u...

    Primary Key Class:

    When deploying an entity bean, we have to specify a primary key for that. This key could be of any type belonging to a java.lang.String or any other java class. In most cases, your primary key class will be a String or some other class that belongs to the java package.

    Creating a Primary Key Class:

    For some entity beans, you will need to define your own primary key class. For example, if a primary key is composed of multiple fields then you must create a primary key class. In the following primary key class, the productId and vendorId fields together uniquely identify an entity bean:

        public class ItemKey implements java.io.Serializable {
           public String productId;
           public String vendorId;

           public ItemKey() { };

           public ItemKey(String productId, String vendorId) {
             this.productId = productId;
             this.vendorId = vendorId;
           public String getProductId() {
              return productId;

          public String getVendorId() {
              return vendorId;
           public boolean equals(Object other) {
              if (other instanceof ItemKey) {
                 return (productId.equals(
                         && vendorId.equals(

              return false;

           public int hashCode() {
              return productId.hashCode();


    Class Requirements:

    A primary key class must meet these requirements:

    ** The access control modifier of the class is public.
    ** All fields are declared as public.
    ** For container-managed persistence, the field names in the primary key class must match the corresponding container-managed fields in the entity bean class.
    ** The class has a public default constructor.
    ** The class implements the hashCode() and equals(Object other) methods.
    ** The class is serializable.

    (ahamed at aztec dot soft dot net)