Primary Key Class on Bigint data type (Websphere 4.0)

Discussions

EJB design: Primary Key Class on Bigint data type (Websphere 4.0)

  1. I am creating a custom primary key class on my table on field of type big int. I have a finder which rerturns a collection, when i iterate on this collection and cast it to the remote object it rerturns me class cast exception
    "java.lang.ClassCastException: org.omg.stub.javax.ejb._EJBObject_Stub org.omg.stub.javax.ejb._EJBObject_Stub "

    The code is below

    Iterator itr = cremote.iterator();
    while(itr.hasNext())
    {
    User obj1 = (User)itr.next();
          out.println("Name is : " + obj1.getName()+"<br>");

    }

    IF any one can guide me how can i resove this problem.
  2. Hi,
      You should not use normal typecasting in rmi. Use the method PortableRemoteObject.narrow() for typecasting.

    Do like this:
    Iterator itr = cremote.iterator();
    while(itr.hasNext())
    {
        Object obj = (EJBObject)itr.next();
        User user = (User)javax.rmi.PortableRemoteObject.narrow(obj, package1.package2.User.class);
    }

    Hope this works...
    Thanks,
    Malar.
  3. Thanx[ Go to top ]

    Hi Malar,
     Thanx this works well. Can you please guide me what is the best practise either to make a custom primary class on table with a single field primary key of types int, long, bigint etc or make a primary key by changing the type of the primitive type to its wrapper class like java.lang.Long, java.lang.Integer etc.

    Any links, documentation will be highly appreicated.
  4. Primary Keys[ Go to top ]

    Hi,
         I always use a seperate key class irrespective of the datatype(int, Date, BigDecimal, etc). This way if you add one more column to the primary key, the changes in the code are minimal(you need to modify the key object to set the new column while calling findByPrimaryKey()). If you had used Wrapper class as the key, then with the above changes you should also modify Home interface, Bean class to modify the return types in many methods.

         By the way, it is my opinion...

    Thanks,
    Malar.