findByPrimaryKey() error


EJB programming & troubleshooting: findByPrimaryKey() error

  1. findByPrimaryKey() error (8 messages)

    Hi everyone,

    I wrote an entity EJB(TestBean), which has a findByPrimaryKey(TestPrimaryKey priKey) method, but I always got a NoSuchMethodError while calling it from a client class. Here is the error message:

    I checked the TestBean.jar file and looked into, which do has findByPrimaryKey() method, the line 57 is:

    57: weblogic.ejb.internal.MethodInfo __mi = findMethodInfo(__methodSig);

    I used Weblogic ejbc to generate those EJB classes.

    Thanks a lot for any help!!!


    Threaded Messages (8)

  2. findByPrimaryKey() error[ Go to top ]

    You may want to verify that the findByPrimaryKey() method is using your custom class as the primary key class, versus using one of the basic types like a string or a primitive type, and that that is what you are passing in the call. Do you have a sample of the call and of the method code?
  3. findByPrimaryKey() error[ Go to top ]

    Thanks Mark,

    I do have a custom class as a primary key. Actually, I've studied a lot of sample codes, and beleive ejb-jar.xml and weblogic-ejb-jar.xml has also been defined corretly, but I have no clue about what's wrong here.
    public class TestBean implements EntityBean {
        EntityContext entityContext;
        public TestPrimaryKey ejbCreate() throws CreateException {
            /**@todo: Implement this method*/
            return null;
        public void ejbPostCreate() throws CreateException {
        public void ejbLoad() {
        public void ejbStore() {
        public void ejbRemove() throws RemoveException {
        public void ejbActivate() {
        public void ejbPassivate() {
        public void setEntityContext(EntityContext entityContext) {
            this.entityContext = entityContext;
        public void unsetEntityContext() {
            entityContext = null;
        public TestPrimaryKey ejbFindByPrimaryKey(TestPrimaryKey primKey) throws ObjectNotFoundException {
            /**@todo: Implement this method*/
            System.out.println("Start looking for Test Ejb:"+primKey.toString());
            return primKey;
    public interface TestHome extends EJBHome {
        public Test create() throws RemoteException, CreateException;
        public Test findByPrimaryKey(TestPrimaryKey primKey) throws ObjectNotFoundException, RemoteException, FinderException;

    public void test(){
       try {
          InitialContext initial = new InitialContext();
          TestHome testHome = (TestHome)PortableRemoteObject.narrow(initial.lookup("Test"), TestHome.class);
          Test test = (Test) PortableRemoteObject.narrow(testHome.findByPrimaryKey(new TestPrimaryKey(102)),Test.class);
       } catch (Exception e){

    Thanks for help!!!


  4. findByPrimaryKey() error[ Go to top ]

    Try changing "ObjectNotFoundException" to "FinderException" in your TestPrimaryKey method signature.

    ie :

    public TestPrimaryKey ejbFindByPrimaryKey(TestPrimaryKey primKey) throws FinderException {
  5. findByPrimaryKey() error[ Go to top ]

    I would also remove the ObjectNotFoundException from the interface definition, at least for now. That may get things working...

  6. findByPrimaryKey() error[ Go to top ]

    1. The same problem ocurred after removing ObjectNotFoundException from the interface definition.

    2. I don't have actual code within the "todo" area.
  7. findByPrimaryKey() error[ Go to top ]

    do u have actual code within the "todo" area?
  8. findByPrimaryKey() error[ Go to top ]

    dude how are you going to return an remote interface without implementing the ejbFind method? you can return null for "findByPrimaryKey".If it couldn't find anything, it will throw the exception. yes you are passing in a primary key, but if you entity bean is not mapping to anything, what is the point of having this primary key, and of course, how can the container *load* the data?

    my suggestion will be to map your entitybean with a dummy table (e.g. a simple user table with username and password),
    then map your bean to this dummy table, and then try to run some test.

    if you are using CMP, you don't have to implement this method. if you are using BMP, then you have to write the actual JDBC call to lookup the data.

    a lot of examples on the net have crazy sql:

    you don't need to do a "SELECT *". you just need to:
    "SELECT [primary key] FROM TABLE".

    this will speed things up, and let the "ejbLoad" method to load the other data.

    i hope that help.
  9. findByPrimaryKey() error[ Go to top ]

    The problem has been solved. It's because of one weblogic jar file didn't included in the classpath.

    Thanks everyone!