Hi Martin,
> Problems appear when I use primitive ints in primary keys for my > objects. When a referenced object has a 0 key "pf.get(object)" returns > null and not the object referenced by the 0 key. > When I use Integer objects as IDs I dont have any trouble... can anyone > tell me why this happens?
This is expected behavior. The problem with primitive types is that they never represent 'null'. So when represents a primitive FK/PK null? When is a reference removed when FK is primitive? Assume you have a reference from A to B and the primitive PK of B is 0 (thus FK in A is 0), how can you reject the reference? The FK in A is already 0?
OJB use the default value of primitive PK,FK fields ('0') as 'null' representation. Thus if you use primitive fields as PK, all values should be != 0.
This is only true for primitive PK/FK fields. All other fields have 'normal' behavior.
regards, Armin
Martin I. Levi wrote:
Hi!
I have a doubt related to PersistentFields and object mappings... here i go:
I obtain a PersistentField from an object in this way: -----------------------code starts here---------------------------------
private void loadFieldValues(BaseBusinessObject object)
throws MetadataException
{
Class attributeType = object.getClass();
MetadataManager mm = MetadataManager.getInstance();
DescriptorRepository dr = mm.copyOfGlobalRepository();
ClassDescriptor cld = dr.getDescriptorFor(attributeType);
FieldDescriptor[] fields = cld.getAllRwFields();
for (int i = 0; i < fields.length; i++) { //the code inside this "for" shows every field from //(this) object and it works great so i omit it. }
Vector references = cld.getObjectReferenceDescriptors();
//the following for creates a recursion //to show every referenced object //from this and the following referenced objects, etc.
for (int i = 0; i < references.size(); i++)
{
ObjectReferenceDescriptor reference =
(ObjectReferenceDescriptor) references.get(i);
System.out.println("-------------- " +
reference.getAttributeName()
+ " -------------");
String attributeName = reference.getAttributeName();
PersistentField pf =
PersistentFieldFactory.createPersistentField(attributeType,attributeName);
BaseBusinessObject objReference = (BaseBusinessObject)
pf.get(object); loadFieldValues(objReference); //recursive call!
}
} -----------------------code ends here---------------------------------
Problems appear when I use primitive ints in primary keys for my objects. When a referenced object has a 0 key "pf.get(object)" returns null and not the object referenced by the 0 key. When I use Integer objects as IDs I dont have any trouble... can anyone tell me why this happens?
Thanks!
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
