In parts of my code I access the primary keys of my persistent bean entities through introspection. All my entities have a method called getId() containing the primary key, but I have come across a situation in which I cannot retrieve the ID using introspection even though regular method invocation of my getId method retrieves it. I am guessing that Hibernate's use of CGLib is the cause of this paradox, but I am not sure.
The code below invokes a getId method through introspection and gets a null. It then invokes the getId() method directly and gets a non null value. All my entities use the "native" ID generator, and the error only occurs on entities which use joined-subclass inheritance (specified in the HBM files).
If anyone can give me a hint to what could be going on here I would be grateful.
Randahl
object = (P) readMethod.invoke(entity);
if(getPropertyName().equals("id"))
logger.info(
"Reading ID from entity " + entity + " with id " +
entity.getId() + " and class " +
entity.getClass().getName() + " and super class " +
entity.getClass().getSuperclass().getName() +
" using read method " + readMethod.getName() +
" and result " +
"was " + object
);
And the output:
12:52:47,656 INFO [PrimitiveMapping] Reading ID from entity dk.rockit.[...].jpg.JpgGraphic@1d61d83 with id 10297 and class
dk.rockit.[...].jpg.JpgGraphic$$EnhancerByCGLIB$$8668af98 and super class dk.rockit.[...].jpg.JpgGraphic using read method getId and result was null
|