Danilo Tommasina wrote:

Hi,

I guess it is always the same problem with 0 and null keys, there are already several posts about this in the mailing list, I guess that a big red text should be put somewhere in the OJB doc (if it isn't already there) :)


It's not there already, but I will put such a 'big red warn' ASAP. Thanks for the hint.


The problem is that primitive types cannot be null, so 0 is interpreted by OJB as null for primitive types, for this reason you do not recieve any results when queriing with a primitive 0 primary key, but works correctly if queriing with an Integer( 0 ).

Also if this may work, you should not use primitive 0 nor Integer( 0 ) as primary key, since OJB (at least in RC4) is/was interpreting also Integer( 0 ) as null when updating objects into db, causing inserts of new objects (PK null) instead of updates (PK = 0). I do not know if this issue has been fixed in RC5 and/or later, sorry.


hmm, this should be fixed. If the problem still exist, please make a bug report.


regards,
Armin


Cheers
Danilo


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]




--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to