Passing J2SE Collections in EJB Remote Methods

Posted Mon, 10 Nov 2003

The J2SE Collection interfaces and abstract classes do not implement the Serializable interface, making it difficult to pass Collections around using EJB Remote Interfaces.

The trick to this one is to be explicit about the type of Collection you want to use. I discovered this problem while implementing the Value List Hander pattern from Sun's J2EE Patterns Catalog. If you're unfamiliar with the pattern, it allows you to iterate over a list of remote entities in an efficient manner, by utilizing the Transfer Object pattern, also from the J2EE Patterns Catalog.

I wrote an Enterprise Java Bean to act as a facade to my VLH objects in the business tier, and found that it was throwing a NotSerializableException when I attempted to return a sublist of a java.util.List reference. The List variable referenced an instance of an ArrayList object, which does implement Serializable, but since I was referencing it as a java.util.List, which does not implement Serializable, the resulting sublist was not Serializable either.

I simply changed the VLH classes to contain a reference to an ArrayList internally instead of a List. This seems to have fixed that problem, hope it helps you with yours!

Related Books

Core J2EE Patterns: Best Practices and Design Strategies (2nd Edition) (Sun Core Series) Head First EJB (Brain-Friendly Study Guides; Enterprise JavaBeans) Effective Java (2nd Edition) (The Java Series) Java Generics and Collections Design Collection Revealed: Adobe InDesign CS3, Photoshop CS3 & Illustrator CS3 (Revealed (Thomson))

Post a Comment




About

My name is Tim Fanelli, I am a software engineer in Northern NY. I spend most of my time working, and when I can, I try to post interesting things here.

Cigar Dossiers