Hi all,
I looking for some advice on how to handle the following scenario:
Say that I have a CMP Entity named "Person" and amoung having several simple fields (such as PersonId, Name, PhoneNumber, etc.) the entity includes a Map of arbitrary name-value pairs that can be associated with the person.
How best to handle the persistence of this Map?
Here's a synopsis of what I've tried/considered:
#1 -
Create a second CMP Entity called "PersonAttribute" with three fields: PersonId, Key, Value. Create a 1-M CMR from the Person entity and this PersonAttribute entity.
Issues: Doesn't work because the PersonId field isn't persisted until the end of the inserts: so if multiple Persons are being stored that have the same sets of attributes in them (the same Keys, but possibly different Values) there is a unique-constraint violation.
#2 -
Same as #1 but add a fourth field to PersonAttribute that is a UID, so that the unique-constraint violation doesn't occur.
Works, but... If I use XDoclet Value Objects (which I'd like to) for these entities then I end up with PersonValue having get/set methods for a Collection (or Set) of PersonAttributeValue objects... which is correct, except I have no Map-Like access to the person's attributes.
I'd really like to be able to make calls like:
personAttributeValue.getPersonAttribute(key) personAttributeValue.setPersonAttribute(key, value)
-- or at least
map = personAttributeValue.getPersonAttributes();
map.get(key);
map.put(key, value);
But instead I have to work something like this:
set = personAttributeValue.getPersonAttributes();
String wantToGet = "someKey";
String theValueIWant = null;
Iterator itr = set.iterator();
while(itr.hasNext()) {
PersonAttributeValue val = (PersonAttributeValue)itr.next();
if(val.getKey().equals(wantToKey)) {
theValueIWant = val.getValue();
break;
}
}
set.put(new PersonAttributeValue(id, key, value));
Doesn't that really suck!?!
#3-
Back to #1, but add a non-CMP field to PersonEntity that is a HashMap that you can get/set through the local/remote interface. Add code in ejbLoad() and ejbStore() to load/store the values in the map.
Works... but... isn't there a better way?
Thanks for any suggestions,
james
------------------------------------------------------- This SF.net email is sponsored by: Etnus, makers of TotalView, The best thread debugger on the planet. Designed with thread debugging features you've never dreamed of, try TotalView 6 free at www.etnus.com. _______________________________________________ xdoclet-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/xdoclet-user
