After some headscratching, I have found a bug in the CDCollection
tutorial. Basically, what happens is that when the tutorial inserts
new CDs, it has logic for detecting whether they already exist. It
tries to throw a CDExistsException to the client in this case. What
actually happened was that a RemoteException got thrown in stead.

The code below is the culprit code from CDCollectionBean.java. Note my
//!! commented line which, if uncommented, is one way of resolving the
problem (even if a bit ugly, but again, this isn't air traffic control
:-). Basically, the CDExistsException gets caught in the immediately
following catch (Exception e) clause and so is treated as if the CD
didn't exist.

Cheers
        Bent D

try
{
    CD oldCd = home.findByPrimaryKey(id);
    String dummy = oldCd.getId(); // Force loading of data here
    // If we get here, the CD is already in the collection
    throw new CDExistsException();
}
// Because we aren't dealing with air traffic control here, I will assume
// that any exception generated from finding whether a CD exists in the
// database is an indication that it doesn't, and therefore it's safe to
// add it.
catch (Exception e)
{
    //!! if (e instanceof CDExistsException) throw (CDExistsException)e;

    System.out.println("Added CD with id=" + id + ", title=" + title
                       + ", artist=" + artist + ", type=" + type + ", notes=" + notes);
    try
        {
            CD cd = home.create(id);
            cd.setTitle(title);
            cd.setArtist(artist);
            cd.setType(type);
            cd.setNotes(notes);
            return;
        }
    catch (Exception e2) {throw new RemoteException (e2.toString());};
}


-- 
Bent Dalager - [EMAIL PROTECTED] - http://www.pvv.org/~bcd
                                    powered by emacs

_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to