db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan Berkel <...@sitadelle.com>
Subject Re: error messages and documentation, was: RE: Strange null pointer e xceptions
Date Wed, 08 Oct 2003 15:53:47 GMT
Oliver,

oliver.matz@ppi.de wrote:

>>>since the NPE is due to missing fields in the metadata,
>>>I assume that a workaround is to add field-descriptors.
>>>      
>>>
>>I added field-descriptors to the class descriptor of the Interface 
>>(Template) and it worked fine, thanks.
>>
>>Actually you need field-descriptors in your Interface and 
>>implementing 
>>class, not in the base class itself (as there can be no instances ?).
>>
>>I think the documentation on the ojb website is not very 
>>clear or even 
>>erroneous on this point.
>>    
>>
>
>I agree that the OJB documentation is not sufficient.
>Personally, I consider valuable error messages (as
>opposed to mysterious NPEs) even more important.
>
>We have to work on that. 
>
I dug a bit deeper in the code to find out why OJB is throwing NPEs 
instead of giving a bit more of a valuable hint.
ClassDescriptor.java:getPkFields()
   
             if (m_isInterface)
             {
                ... // look for implementor classes and return their 
PkFields
             }
            // 1.b if not an interface The classdescriptor must have 
FieldDescriptors
            else
            {
                fields = getFieldDescriptions();
            }

            // now collect all PK fields
            for (int i = 0; i < fields.length; i++)
                                             ^^^ NPE

actually it was taking the interface for a real class and tried to get 
its field descriptors, which obviously failed.
m_isInterface is set by RepositoryXmlHandler:

             if (table == null)
             {
                       m_CurrentCLD.setIsInterface(true);
             }

So if there is no table definition for a class-descriptor entry in 
repository_user.xml, the class will be automatically declared as an 
interface.

In my example the xdoclet-ojb module automatically creates the 
table="..." entry unless you specify generate-table-info="false".

To avoid confusion, I have some suggestions:
1) make repository_user more explicit regarding the difference between 
class/interface
    or
2) make xdoclet-ojb more intelligent (e.g. never generate table info for 
interfaces or issue a warning when doing so)
3) state explicitely in the doc that including table infos for an 
interface will result in errors

I am willing to work on a patch for 2) but I haven't checked if the 
xdoclet code is already in the CVS.

I suggest moving the thread to ojb-dev.

regards,
   Jan

>  
>
>><SNIP from http://db.apache.org/ojb/tutorial3.html#extents>
>>    1.  A declaration for InterfaceArticle, defining which classes 
>>implement this interface:
>>
>><!-- Definitions for org.apache.ojb.broker.InterfaceArticle -->
>>    <class-descriptor class="org.apache.ojb.broker.InterfaceArticle">
>>       <extent-class class-ref="org.apache.ojb.broker.Article" />
>>       <extent-class class-ref="org.apache.ojb.broker.BookArticle" />
>>       <extent-class class-ref="org.apache.ojb.broker.CdArticle" />
>>    </class-descriptor>
>></SNIP>
>>
>>It doesn't give a hint to include field-descriptors for the 
>>interface,  or does my setup just happen to be special ?
>>    
>>
>
>
>  
>
>>Moreover, having the obligation to add field descriptors to the 
>>interface is not very practical when using the xdoclet-ojb 
>>module (where 
>>you have to define the mappings on the instance fields), or 
>>is there a workaround ?
>>    
>>
>
>Sorry, I have no experience with the xdoclet-ojb module.
>You might start a new thread with that question.
>
>Olli
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>For additional commands, e-mail: ojb-user-help@db.apache.org
>
>  
>



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message