Hello,
 
I'm having some problems with transactions.
 
A short overview of my model. I'm using an InstantDB database and i have implemented some entity beans.
One of them is the entity bean Basket with the following fields: oid (order id), pid (product id) and quantity.
De entity bean 'Basket corresponds to the tablename 'Basket'.
The product id 'pid' is the primary key of the entity bean 'CompactDisc' or 'Book'.
The order id 'oid' is the primary key of the entity bean 'Order'.
Both 'oid' and 'pid' are the primary key of the entity bean basket.
 
I implemented a Sesionbean, where 3 basket items are created. (1,13356,1) , (1,43167,1) and (1,42136,1)
So no problems so far. The table is updated correctly.
But when i want to list the three basket items, i get three times the first item, in this case (1,13356,1).
I have included some code of the client application of the session bean and some code of the session bean.
 
// This is some code from the client app of the session bean where a want to list the three basket items
// The problem is not situated in this code but in the function 'getBasketItems()' (see below) which
// returns a vector of remote interfaces of the entity bean 'Basket'
// The vector contains allready three times the same object.
System.out.println("Getting a list of items");
System.out.println("-----------------------");
 try {
     Vector list=cs.getBasketItems(); // here is the problem i think (cs is an instance of the sessionbean)
     int size = list.size();
     for(int i=0;i<size;i++){
          Basket item = (Basket)list.elementAt(i);
          long id = item.getProductID();
          int quantity = item.getQuantity();
          int group = cs.getGroup(id);   // method in the sessionbean
 
          if(group == 0){
           CompactDisc cd = (CompactDisc) cs.getCompactDisc(id);
           System.out.println(cd.getArtist()+" "+cd.getTitle()+" "+item.getQuantity());
          }
          if(group == 1){
           Book book = (Book) cs.getBook(id);
           System.out.println(book.getAuthor()+" "+book.getTitle()+" "+item.getQuantity());
          }
     }
    
 }
catch (Exception e) {
     System.err.println("exception during transaction: " + e);
     System.exit(2);
 }
 
 
// This some code of the sessionbean 'CustSessionBean'
// Here is the problem i think. It must be something with the findmethod
// findByOrderID(long) which returns an enumeration of remoteinterfaces of basket
//
public Vector getBasketItems() throws RemoteException {
     Vector list = new Vector();
     if(bhome == null)
          setBasketHomeInterface("BasketBeanHome");  // this checks whether the homeinterface is set, no prob with that
 
 try{
      long o = getOrderID(); // the order id is kept by the sessionbean, when the an order is created
      Enumeration items = bhome.findByOrderID(o); // --> THE PROBLEM (*)
      while(items.hasMoreElements()){
           Basket item = (Basket) items.nextElement();
           System.out.println(item);                    --->     (**)
           list.addElement((Basket) item);
      }
      return list; // this list allready contains three times the same object
 }
 catch(FinderException e){
  return null;
 }
}
 
(*)
When i look at the transactions of to the database, i get the following by calling findByOrderID(long):
...select oid,pid from Basket where oid=1
...select oid,pid,quantity from basket where oid=1 and pid=13356  ----> ?????????
i don't know why pid is set to 13356. Is it because oid and pid are primary key for basket?
So every time i look for basket items in the table the 'pid' is set to the first productid in the table
in this case 13356.
 
 
 
(**)
 When a write the item i get the following: (3 times)
basket.JOnASBasketBeanBasket_Stub[RemoteStub[ref:[end point:[134.58.40.2:48568](remote),objID:[13]]]]
basket.JOnASBasketBeanBasket_Stub[RemoteStub[ref:[end point:[134.58.40.2:48568](remote),objID:[13]]]]
basket.JOnASBasketBeanBasket_Stub[RemoteStub[ref:[end point:[134.58.40.2:48568](remote),objID:[13]]]]
So the vector contains three times the same item i guess...
 
I hope you understand what i want to tell you.
I don't know whether the problem is something to do with the primary key of the entity bean 'Basket'
or with the findByOrderID of the homeinterface of the bean 'Basket'.
How can i solve this problem??
 
Thnx
 
Jochen Vastmans

Reply via email to