FindByPrimaryKey has returned more than one value error

Discussions

EJB programming & troubleshooting: FindByPrimaryKey has returned more than one value error

  1. I am currently using EJB CMP2.0 and have written a JUnit test page. (Weblogic server 6.1 SP3)

    There is a record in the DB with a primary key N

    When I call the remove and get the record using the FindByPrimaryKey I get an error..

    FindByPrimaryKey has returned more than one value. This violates the EJB CMP2.0 specs..

    Has anyone ran into this?
    I am assuming that something is stuck in cache that says there is an extra bean for that primarykey??
    Any time I use the FindByPrimaryKey for that record gives the same error.

    JUnit Test Page:
    public void testRemoveOrg()
    throws Exception
    {
    System.out.println("**********************************");
    System.out.println("* TEST REMOVE *");

    System.out.println("**********************************");
    System.out.println("");
    try
    {
      transaction.begin();
      System.out.println("[TestOrgEntity.testRemoveOrg()] Org id is " + orgObjId);

      OrgPK orgPK = new OrgPK();
      //Set the PK id to the current record (Use PK Class)
      orgPK.id = "The Org Test";
      //Load the record from the DB
      Org oci = (Org) orgHome.findByPrimaryKey(orgPK);
      System.out.println(oci.getId());
      //call the remove method of the Business interface
      oci.remove();
      transaction.commit();
    }
    catch(Exception e)
    {
      System.out.println(">> ERROR: RemoveOrg: "+e);
      transaction.rollback();
      throw e;
    }
    } // testRemoveDocCatalog


    Record is never removed from DB.. Error on the FindByPrimaryKey method.
    Any help would be appreciated.
  2. In Weblogic as a default the results of finders do not include the results of updates during the current transaction. To overide this you have to specifiy the <include-updates>True in the weblogic-cmp-rdbms-jar.xml file.

    David
  3. The record already exists in the DB.. So there was no previous transaction that was not commited..

    I am just doing a FindByPrimaryKey and it gives the same result for any primary key at this point..
    I know that my JUNIT Test code works because others can run it..
    It is like my cache has been corrupted or something??

    Alison
  4. Solved...

    It turns out that once I upgraded from WL server 6.1 SP 3 to SP 4 it resolved the problem...

    Hope this helps someone..