hi all-
i am pretty new at ejb and that might be a little off topic but here i go.
instead of creating entity beans the conventional way, according to spec,
would it be desirable to have one type of entity bean with a hashtable
member to manipulate all the values and fields dynamically, accessing fields
by their string names.
class ValueObject
{
String name;
Object value;
}
class BaseEntityBean
{
String id;
Hashtable fields; //collection of ValueObjects, one row of data becomes
"columncount" times ValueObjects.
setField(String name, Object value);
Object getField(String name);
String getAsXML();
BaseEntityBean findByPrimaryKey; //finds record, fills the "fields"
variable using ResultSetMetaData
}
so for each different type of entity beans, we can inherit from
BaseEntityBean, to create for instance AccountEntityBean that knows from
which table it's going to get values.
one obvious advantage is simplicity. one doesn't have to code setters and
getters for all fields. another one would be addition of "custom" fields by
the user later on. when he does that custom fields would be equal to what's
already defined in the bean. hence no different way to handle custom fields.
then again, obvious disadvantage is speed. instantiating the ValueObjects
and filling the hashtable takes more time. also, we are no longer using the
simple types for the sake of genericity which doesn't help the speed issue
either.
question is whether the benefits outweigh the speed disadvantage or not.
also, is there anything against exposing a ResultSet type from an entity
bean?
i appreciate any input, thanks.
--a