You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Raymond Barlow <rb...@raymanoz.com> on 2003/05/20 15:56:15 UTC

trying to implement inheritance-but failing!

Hi All,

After recently reading about being able to perform vertical inheritance 
with the use of "this" in the reference-descriptor, I've been busy 
trying to get it to work, but so far have had no luck :(

I think that maybe I've just misinterpreted something, or misunderstood 
one of the pas emails. But anyway, following is how I've done it 
(unsuccessfully). Any help appreciated:

Classes:

public class Entity
{
    Integer oid;
}

public class User extends Entity
{
    String userName;
    String password;
      etc...
}

public class Employee extends User
{
    Date startedWork;
       etc...
}
 
repository_user.xml:

   <class-descriptor
         class="com.company.entity.User"
         table="User">
      <extent-class class-ref="com.company.entity.Employee"/>
      <field-descriptor
         name="oid"
         column="userId"
         jdbc-type="INTEGER"
         primarykey="true"
         autoincrement="true"/>
      <field-descriptor
         name="userName"
         column="userName"
         jdbc-type="VARCHAR"/>
      <field-descriptor
         name="password"
         column="password"
         jdbc-type="VARCHAR"/>
        etc...      
   </class-descriptor> 

   <class-descriptor
         class="com.company.entity.Employee"
         table="Employee">
     <field-descriptor
         name="oid"
         column="userId"
         jdbc-type="INTEGER"
         primarykey="true"/>
      <field-descriptor
         name="startedWork"
         column="startedWork"
         jdbc-type="DATE"/>
          etc...
      <reference-descriptor
         name="this"
         class-ref="com.company.entity.User"
         auto-retrieve="true" auto-update="true" auto-delete="true">
         <foreignkey field-ref="oid"/>
      </reference-descriptor>
   </class-descriptor>
 
when I try to do a search in "User" type, (expecting an Employee to be 
returned), the moment I call broker.getCollectionByQuery(query), I get 
the following stack trace:

Caused by: java.lang.NullPointerException
    at 
org.apache.ojb.broker.metadata.ClassDescriptor.getObjectReferenceDescriptorByName(Unknown 
Source)
    at 
org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.getFieldDescriptor(Unknown 
Source)
    at 
org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.getColName(Unknown 
Source)
    at 
org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendColName(Unknown 
Source)
    at 
org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendSelectionCriteria(Unknown 
Source)
    at 
org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendCriteria(Unknown 
Source)
    at 
org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendSQLClause(Unknown 
Source)
    at 
org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.asSQLStatement(Unknown 
Source)
    at 
org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendClause(Unknown 
Source)
    at 
org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendWhereClause(Unknown 
Source)
    at 
org.apache.ojb.broker.accesslayer.sql.SqlSelectStatement.getStatement(Unknown 
Source)
    at 
org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl.getPreparedSelectStatement(Unknown 
Source)
    at 
org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeQuery(Unknown 
Source)
    at org.apache.ojb.broker.accesslayer.RsIterator.<init>(Unknown Source)
    at 
org.apache.ojb.broker.core.RsIteratorFactoryImpl.createRsIterator(Unknown 
Source)
    at 
org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery(Unknown 
Source)
    at 
org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery(Unknown 
Source)
    at 
org.apache.ojb.broker.core.PersistenceBrokerImpl.getIteratorFromQuery(Unknown 
Source)
    at 
org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Unknown 
Source)
    ... 42 more

Any ideas?

--
Regards,
Raymond Barlow



Re: trying to implement inheritance-but failing!

Posted by Raymond Barlow <rb...@raymanoz.com>.
Thanks for replying Jakob,

I did this because of an earlier thread (titled "Extend best practice"), 
Houari Tine said:

 >Vertical inheritance is possible with last release of OJB. You must use
 >"this" as reference descriptor.


I think changing this name would break the inserts, yeah?

-Raymond



Jakob Braeuchi wrote:

> hi raymond,
>
> what do you expect when using "this" as the name of the relationship ?
> does it work with a different name ?
>
> jakob
>
> Raymond Barlow wrote:
>
>> Hi All,
>>
>> After recently reading about being able to perform vertical 
>> inheritance with the use of "this" in the reference-descriptor, I've 
>> been busy trying to get it to work, but so far have had no luck :(
>>
>> I think that maybe I've just misinterpreted something, or 
>> misunderstood one of the pas emails. But anyway, following is how 
>> I've done it (unsuccessfully). Any help appreciated:
>>
>> Classes:
>>
>> public class Entity
>> {
>>    Integer oid;
>> }
>>
>> public class User extends Entity
>> {
>>    String userName;
>>    String password;
>>      etc...
>> }
>>
>> public class Employee extends User
>> {
>>    Date startedWork;
>>       etc...
>> }
>>
>> repository_user.xml:
>>
>>   <class-descriptor
>>         class="com.company.entity.User"
>>         table="User">
>>      <extent-class class-ref="com.company.entity.Employee"/>
>>      <field-descriptor
>>         name="oid"
>>         column="userId"
>>         jdbc-type="INTEGER"
>>         primarykey="true"
>>         autoincrement="true"/>
>>      <field-descriptor
>>         name="userName"
>>         column="userName"
>>         jdbc-type="VARCHAR"/>
>>      <field-descriptor
>>         name="password"
>>         column="password"
>>         jdbc-type="VARCHAR"/>
>>        etc...        </class-descriptor>
>>   <class-descriptor
>>         class="com.company.entity.Employee"
>>         table="Employee">
>>     <field-descriptor
>>         name="oid"
>>         column="userId"
>>         jdbc-type="INTEGER"
>>         primarykey="true"/>
>>      <field-descriptor
>>         name="startedWork"
>>         column="startedWork"
>>         jdbc-type="DATE"/>
>>          etc...
>>      <reference-descriptor
>>         name="this"
>>         class-ref="com.company.entity.User"
>>         auto-retrieve="true" auto-update="true" auto-delete="true">
>>         <foreignkey field-ref="oid"/>
>>      </reference-descriptor>
>>   </class-descriptor>
>>
>> when I try to do a search in "User" type, (expecting an Employee to 
>> be returned), the moment I call broker.getCollectionByQuery(query), I 
>> get the following stack trace:
>>
>> Caused by: java.lang.NullPointerException
>>    at 
>> org.apache.ojb.broker.metadata.ClassDescriptor.getObjectReferenceDescriptorByName(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.getFieldDescriptor(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.getColName(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendColName(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendSelectionCriteria(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendCriteria(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendSQLClause(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.asSQLStatement(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendClause(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendWhereClause(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.accesslayer.sql.SqlSelectStatement.getStatement(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl.getPreparedSelectStatement(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeQuery(Unknown 
>> Source)
>>    at org.apache.ojb.broker.accesslayer.RsIterator.<init>(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.core.RsIteratorFactoryImpl.createRsIterator(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.core.PersistenceBrokerImpl.getIteratorFromQuery(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Unknown 
>> Source)
>>    ... 42 more
>>
>> Any ideas?
>>
>> -- 
>> Regards,
>> Raymond Barlow
>>
>>
>>
>> ---------------------------------------------------------------------
>> 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-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>

-- 
Regards,
Raymond Barlow
--------------------------------------
(For contact details, please email me)




Re: trying to implement inheritance-but failing!

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi raymond,

what do you expect when using "this" as the name of the relationship ?
does it work with a different name ?

jakob

Raymond Barlow wrote:

> Hi All,
>
> After recently reading about being able to perform vertical 
> inheritance with the use of "this" in the reference-descriptor, I've 
> been busy trying to get it to work, but so far have had no luck :(
>
> I think that maybe I've just misinterpreted something, or 
> misunderstood one of the pas emails. But anyway, following is how I've 
> done it (unsuccessfully). Any help appreciated:
>
> Classes:
>
> public class Entity
> {
>    Integer oid;
> }
>
> public class User extends Entity
> {
>    String userName;
>    String password;
>      etc...
> }
>
> public class Employee extends User
> {
>    Date startedWork;
>       etc...
> }
>
> repository_user.xml:
>
>   <class-descriptor
>         class="com.company.entity.User"
>         table="User">
>      <extent-class class-ref="com.company.entity.Employee"/>
>      <field-descriptor
>         name="oid"
>         column="userId"
>         jdbc-type="INTEGER"
>         primarykey="true"
>         autoincrement="true"/>
>      <field-descriptor
>         name="userName"
>         column="userName"
>         jdbc-type="VARCHAR"/>
>      <field-descriptor
>         name="password"
>         column="password"
>         jdbc-type="VARCHAR"/>
>        etc...        </class-descriptor>
>   <class-descriptor
>         class="com.company.entity.Employee"
>         table="Employee">
>     <field-descriptor
>         name="oid"
>         column="userId"
>         jdbc-type="INTEGER"
>         primarykey="true"/>
>      <field-descriptor
>         name="startedWork"
>         column="startedWork"
>         jdbc-type="DATE"/>
>          etc...
>      <reference-descriptor
>         name="this"
>         class-ref="com.company.entity.User"
>         auto-retrieve="true" auto-update="true" auto-delete="true">
>         <foreignkey field-ref="oid"/>
>      </reference-descriptor>
>   </class-descriptor>
>
> when I try to do a search in "User" type, (expecting an Employee to be 
> returned), the moment I call broker.getCollectionByQuery(query), I get 
> the following stack trace:
>
> Caused by: java.lang.NullPointerException
>    at 
> org.apache.ojb.broker.metadata.ClassDescriptor.getObjectReferenceDescriptorByName(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.getFieldDescriptor(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.getColName(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendColName(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendSelectionCriteria(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendCriteria(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendSQLClause(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.asSQLStatement(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendClause(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendWhereClause(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlSelectStatement.getStatement(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl.getPreparedSelectStatement(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeQuery(Unknown 
> Source)
>    at org.apache.ojb.broker.accesslayer.RsIterator.<init>(Unknown Source)
>    at 
> org.apache.ojb.broker.core.RsIteratorFactoryImpl.createRsIterator(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.core.PersistenceBrokerImpl.getIteratorFromQuery(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Unknown 
> Source)
>    ... 42 more
>
> Any ideas?
>
> -- 
> Regards,
> Raymond Barlow
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>


Re: trying to implement inheritance-but failing!

Posted by Raymond Barlow <rb...@raymanoz.com>.
One more thing....

Interestingly enough, I can insert into the tables OK using OJB and this 
setup. I think maybe it has something to do with polymophism (extent-class).

-Raymond

Raymond Barlow wrote:

> Hi All,
>
> After recently reading about being able to perform vertical 
> inheritance with the use of "this" in the reference-descriptor, I've 
> been busy trying to get it to work, but so far have had no luck :(

<snip>




Re: trying to implement inheritance-but failing!

Posted by Raymond Barlow <rb...@raymanoz.com>.
OK, I've stepped through the code (hooray for open source), and I've 
localised it down to this line in 
org.apache.ojb.broker.metadata.ClassDescriptor.getObjectReferenceDescriptorByName: 
(line 421)

    if (ord.getPersistentField().getName().equals(name))

The reason it throws a null pointer exception is that the getName() 
returns null. The name in my repository_user.xml for this 
reference-descriptor is "this", but here it is null. The other 
reference-descriptor fields that are not "this" all seem to work OK, and 
have the correct name at this point.

Should the name of the reference-descriptor 
(AnonymousPersistentFieldForInheritance) be getting populated at some 
point before the code gets here? I'm not sure what normally populates 
this code, but if someone can point me in the right direction, I'd be a 
happy chappy :)

Cheers,
Raymond Barlow
   

Raymond Barlow wrote:

> Hi All,
>
> After recently reading about being able to perform vertical 
> inheritance with the use of "this" in the reference-descriptor, I've 
> been busy trying to get it to work, but so far have had no luck :(
>
> I think that maybe I've just misinterpreted something, or 
> misunderstood one of the pas emails. But anyway, following is how I've 
> done it (unsuccessfully). Any help appreciated:
>
> Classes:
>
> public class Entity
> {
>    Integer oid;
> }
>
> public class User extends Entity
> {
>    String userName;
>    String password;
>      etc...
> }
>
> public class Employee extends User
> {
>    Date startedWork;
>       etc...
> }
>
> repository_user.xml:
>
>   <class-descriptor
>         class="com.company.entity.User"
>         table="User">
>      <extent-class class-ref="com.company.entity.Employee"/>
>      <field-descriptor
>         name="oid"
>         column="userId"
>         jdbc-type="INTEGER"
>         primarykey="true"
>         autoincrement="true"/>
>      <field-descriptor
>         name="userName"
>         column="userName"
>         jdbc-type="VARCHAR"/>
>      <field-descriptor
>         name="password"
>         column="password"
>         jdbc-type="VARCHAR"/>
>        etc...        </class-descriptor>
>   <class-descriptor
>         class="com.company.entity.Employee"
>         table="Employee">
>     <field-descriptor
>         name="oid"
>         column="userId"
>         jdbc-type="INTEGER"
>         primarykey="true"/>
>      <field-descriptor
>         name="startedWork"
>         column="startedWork"
>         jdbc-type="DATE"/>
>          etc...
>      <reference-descriptor
>         name="this"
>         class-ref="com.company.entity.User"
>         auto-retrieve="true" auto-update="true" auto-delete="true">
>         <foreignkey field-ref="oid"/>
>      </reference-descriptor>
>   </class-descriptor>
>
> when I try to do a search in "User" type, (expecting an Employee to be 
> returned), the moment I call broker.getCollectionByQuery(query), I get 
> the following stack trace:
>
> Caused by: java.lang.NullPointerException
>    at 
> org.apache.ojb.broker.metadata.ClassDescriptor.getObjectReferenceDescriptorByName(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.getFieldDescriptor(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.getColName(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendColName(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendSelectionCriteria(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendCriteria(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendSQLClause(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.asSQLStatement(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendClause(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendWhereClause(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlSelectStatement.getStatement(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl.getPreparedSelectStatement(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeQuery(Unknown 
> Source)
>    at org.apache.ojb.broker.accesslayer.RsIterator.<init>(Unknown Source)
>    at 
> org.apache.ojb.broker.core.RsIteratorFactoryImpl.createRsIterator(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.core.PersistenceBrokerImpl.getIteratorFromQuery(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Unknown 
> Source)
>    ... 42 more
>
> Any ideas?
>
> -- 
> Regards,
> Raymond Barlow
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>

-- 
Regards,
Raymond Barlow




Re: trying to implement inheritance-but failing!

Posted by Raymond Barlow <rb...@raymanoz.com>.
Hi Thomas,

Are you saying that there might be a problem with me using anonymous 
fields in this instance? Should I go back and put the FK-Id fields back 
into my classes to get it to work? I could give this a try for now, and 
see how it goes...

Also, I am willing to contribute to documentation on the virtical 
inheritance side OJB. I assume that it would go in as part of Tutorial 3 
(Advanced O/R Mappings). But first, I'd have to be happy that I know how 
it works, and be able to get this search working.

Cheers,
Raymond Barlow

Thomas Mahler wrote:

> Hi Raymond,
>
> There is currently some docuemnation on using anonymous fields for 
> mapping references avaliable at:
> http://cvs.apache.org/viewcvs/db-ojb/xdocs/howto-use-anonymous-keys.xml?rev=HEAD&content-type=text/vnd.viewcvs-markup.
>
> Unfortunately there is currently no documentation or sample code for 
> vertical inheritance. The only we have is the sample given by Tine on 
> the user list some time ago.
>
> I hope we will have some docu on this feature out soon.
>
> cheers,
> Thomas
>
> Raymond Barlow wrote:
>
>> OK, further to this, if I remove the "this" reference (shown below) 
>> descriptor from Employee mapping, I can query on Employee OK (but, of 
>> course, I cannot see any of the User fields). Have I mapped Employee 
>> correctly?? Has anyone else been successful in implementing vertical 
>> inheritance? Can someone please point me to some documentation, give 
>> me an example, or drop me a few more hints on how to get virtical 
>> inheritance working using a reference-descriptor of "this"? :)
>>
>> Regards,
>> Raymond Barlow
>>
>> removed this:
>>      <reference-descriptor
>>         name="this"
>>         class-ref="com.company.entity.User"
>>         auto-retrieve="true" auto-update="true" auto-delete="true">
>>         <foreignkey field-ref="oid"/>
>>      </reference-descriptor>
>>
>> Raymond Barlow wrote:
>>
>>> Hi again,
>>>
>>> Some further tests, and I've found out:
>>> * If I remove the extent-class elements, I can query on User, and 
>>> return an object OK
>>> * (still with no extent-class), If I query on Employee directly, 
>>> same results (ie. exception, same stack trace).
>>>
>>> This makes me think that I've defined my mapping incorrectly. But, I 
>>> can still create new Empoyee objects and persist them OK. I don't 
>>> really know the internals of OJB, but from the stack trace, it looks 
>>> like it is trying to get a field reference, or a class reference, 
>>> and failing (with NullPointer). Could it have something to do with 
>>> the anonymous fields that I've created in my mapping? (I didn't 
>>> include that part in the earlier post).
>>>
>>> -Raymond Barlow
>>>
>>> Raymond Barlow wrote:
>>>
>>>> Hi All,
>>>>
>>>> After recently reading about being able to perform vertical 
>>>> inheritance with the use of "this" in the reference-descriptor, 
>>>> I've been busy trying to get it to work, but so far have had no 
>>>> luck :(
>>>>
>>>> I think that maybe I've just misinterpreted something, or 
>>>> misunderstood one of the pas emails. But anyway, following is how 
>>>> I've done it (unsuccessfully). Any help appreciated:
>>>>
>>>> Classes:
>>>>
>>>> public class Entity
>>>> {
>>>>    Integer oid;
>>>> }
>>>>
>>>> public class User extends Entity
>>>> {
>>>>    String userName;
>>>>    String password;
>>>>      etc...
>>>> }
>>>>
>>>> public class Employee extends User
>>>> {
>>>>    Date startedWork;
>>>>       etc...
>>>> }
>>>>
>>>> repository_user.xml:
>>>>
>>>>   <class-descriptor
>>>>         class="com.company.entity.User"
>>>>         table="User">
>>>>      <extent-class class-ref="com.company.entity.Employee"/>
>>>>      <field-descriptor
>>>>         name="oid"
>>>>         column="userId"
>>>>         jdbc-type="INTEGER"
>>>>         primarykey="true"
>>>>         autoincrement="true"/>
>>>>      <field-descriptor
>>>>         name="userName"
>>>>         column="userName"
>>>>         jdbc-type="VARCHAR"/>
>>>>      <field-descriptor
>>>>         name="password"
>>>>         column="password"
>>>>         jdbc-type="VARCHAR"/>
>>>>        etc...        </class-descriptor>
>>>>   <class-descriptor
>>>>         class="com.company.entity.Employee"
>>>>         table="Employee">
>>>>     <field-descriptor
>>>>         name="oid"
>>>>         column="userId"
>>>>         jdbc-type="INTEGER"
>>>>         primarykey="true"/>
>>>>      <field-descriptor
>>>>         name="startedWork"
>>>>         column="startedWork"
>>>>         jdbc-type="DATE"/>
>>>>          etc...
>>>>      <reference-descriptor
>>>>         name="this"
>>>>         class-ref="com.company.entity.User"
>>>>         auto-retrieve="true" auto-update="true" auto-delete="true">
>>>>         <foreignkey field-ref="oid"/>
>>>>      </reference-descriptor>
>>>>   </class-descriptor>
>>>>
>>>> when I try to do a search in "User" type, (expecting an Employee to 
>>>> be returned), the moment I call broker.getCollectionByQuery(query), 
>>>> I get the following stack trace:
>>>>
>>>> Caused by: java.lang.NullPointerException
>>>>    at 
>>>> org.apache.ojb.broker.metadata.ClassDescriptor.getObjectReferenceDescriptorByName(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.getFieldDescriptor(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.getColName(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendColName(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendSelectionCriteria(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendCriteria(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendSQLClause(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.asSQLStatement(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendClause(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendWhereClause(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.accesslayer.sql.SqlSelectStatement.getStatement(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl.getPreparedSelectStatement(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeQuery(Unknown 
>>>> Source)
>>>>    at org.apache.ojb.broker.accesslayer.RsIterator.<init>(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.core.RsIteratorFactoryImpl.createRsIterator(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.core.PersistenceBrokerImpl.getIteratorFromQuery(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Unknown 
>>>> Source)
>>>>    ... 42 more
>>>>
>>>> Any ideas?
>>>>
>>>> -- 
>>>> Regards,
>>>> Raymond Barlow
>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> 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-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>

-- 
Regards,
Raymond Barlow
--------------------------------------
(For contact details, please email me)



Re: trying to implement inheritance-but failing!

Posted by Raymond Barlow <rb...@raymanoz.com>.
Hi Thomas

>>
>> It is definately something to do with the use of the "this" reference 
>> descriptor. I guess now my only choice left is to integrate the 
>> source code into my project, and step debug the code (yay!) :)
>
>
> That's another reason for opensource: it gives you the full joy of 
> source level debugging :-)

Well, trying to integrate the source code into my project, still finding 
other classes etc that I need........but, getting there...

>> Have you ever successfully done a query/search to retreive a class 
>> which has implementes vertical inheritance? (Like I've said before, 
>> persistence works beautifully, retrieval doesn't.)
>
>
> No, I don't have any experience with the vertical inheritance 
> mechanism Tine developed. There are also no testcases that cover it.
> This has definitely to be written!
>
> Tine promised to deliver tests and docu but I've not seen them so far :-(
>
Well, I eargerly await the release of this docco and the test!!!

Cheers,
Raymond Barlow



Re: trying to implement inheritance-but failing!

Posted by Thomas Mahler <th...@web.de>.
Hi Raymond,

Raymond Barlow wrote:
> Hi again,
> 
> Well, just to keep you up to date (if anyone is interested), 

Sure we are :-)

> I added the 
> FK Id fields back into my classes, removed the anonymous field access, 
> and I still get the same stack trace and exception.
> 
> It is definately something to do with the use of the "this" reference 
> descriptor. I guess now my only choice left is to integrate the source 
> code into my project, and step debug the code (yay!) :)

That's another reason for opensource: it gives you the full joy of 
source level debugging :-)

> Thomas (if you're reading this!):

Yes I do, but with several hours delay. I'm currently offline most of 
the time for a special project situation I face these days...

> Have you ever successfully done a 
> query/search to retreive a class which has implementes vertical 
> inheritance? (Like I've said before, persistence works beautifully, 
> retrieval doesn't.)

No, I don't have any experience with the vertical inheritance mechanism 
Tine developed. There are also no testcases that cover it.
This has definitely to be written!

Tine promised to deliver tests and docu but I've not seen them so far :-(

cheers,
Thomas

> 
> Regards,
> Raymond Barlow
> 
> Thomas Mahler wrote:
> 
>> Hi Raymond,
>>
>> There is currently some docuemnation on using anonymous fields for 
>> mapping references avaliable at:
>> http://cvs.apache.org/viewcvs/db-ojb/xdocs/howto-use-anonymous-keys.xml?rev=HEAD&content-type=text/vnd.viewcvs-markup. 
>>
>>
>> Unfortunately there is currently no documentation or sample code for 
>> vertical inheritance. The only we have is the sample given by Tine on 
>> the user list some time ago.
>>
>> I hope we will have some docu on this feature out soon.
>>
>> cheers,
>> Thomas
>>
>> Raymond Barlow wrote:
>>
>>> OK, further to this, if I remove the "this" reference (shown below) 
>>> descriptor from Employee mapping, I can query on Employee OK (but, of 
>>> course, I cannot see any of the User fields). Have I mapped Employee 
>>> correctly?? Has anyone else been successful in implementing vertical 
>>> inheritance? Can someone please point me to some documentation, give 
>>> me an example, or drop me a few more hints on how to get virtical 
>>> inheritance working using a reference-descriptor of "this"? :)
>>>
>>> Regards,
>>> Raymond Barlow
>>>
>>> removed this:
>>>      <reference-descriptor
>>>         name="this"
>>>         class-ref="com.company.entity.User"
>>>         auto-retrieve="true" auto-update="true" auto-delete="true">
>>>         <foreignkey field-ref="oid"/>
>>>      </reference-descriptor>
>>>
>>> Raymond Barlow wrote:
>>>
>>>> Hi again,
>>>>
>>>> Some further tests, and I've found out:
>>>> * If I remove the extent-class elements, I can query on User, and 
>>>> return an object OK
>>>> * (still with no extent-class), If I query on Employee directly, 
>>>> same results (ie. exception, same stack trace).
>>>>
>>>> This makes me think that I've defined my mapping incorrectly. But, I 
>>>> can still create new Empoyee objects and persist them OK. I don't 
>>>> really know the internals of OJB, but from the stack trace, it looks 
>>>> like it is trying to get a field reference, or a class reference, 
>>>> and failing (with NullPointer). Could it have something to do with 
>>>> the anonymous fields that I've created in my mapping? (I didn't 
>>>> include that part in the earlier post).
>>>>
>>>> -Raymond Barlow
>>>>
>>>> Raymond Barlow wrote:
>>>>
>>>>> Hi All,
>>>>>
>>>>> After recently reading about being able to perform vertical 
>>>>> inheritance with the use of "this" in the reference-descriptor, 
>>>>> I've been busy trying to get it to work, but so far have had no 
>>>>> luck :(
>>>>>
>>>>> I think that maybe I've just misinterpreted something, or 
>>>>> misunderstood one of the pas emails. But anyway, following is how 
>>>>> I've done it (unsuccessfully). Any help appreciated:
>>>>>
>>>>> Classes:
>>>>>
>>>>> public class Entity
>>>>> {
>>>>>    Integer oid;
>>>>> }
>>>>>
>>>>> public class User extends Entity
>>>>> {
>>>>>    String userName;
>>>>>    String password;
>>>>>      etc...
>>>>> }
>>>>>
>>>>> public class Employee extends User
>>>>> {
>>>>>    Date startedWork;
>>>>>       etc...
>>>>> }
>>>>>
>>>>> repository_user.xml:
>>>>>
>>>>>   <class-descriptor
>>>>>         class="com.company.entity.User"
>>>>>         table="User">
>>>>>      <extent-class class-ref="com.company.entity.Employee"/>
>>>>>      <field-descriptor
>>>>>         name="oid"
>>>>>         column="userId"
>>>>>         jdbc-type="INTEGER"
>>>>>         primarykey="true"
>>>>>         autoincrement="true"/>
>>>>>      <field-descriptor
>>>>>         name="userName"
>>>>>         column="userName"
>>>>>         jdbc-type="VARCHAR"/>
>>>>>      <field-descriptor
>>>>>         name="password"
>>>>>         column="password"
>>>>>         jdbc-type="VARCHAR"/>
>>>>>        etc...        </class-descriptor>
>>>>>   <class-descriptor
>>>>>         class="com.company.entity.Employee"
>>>>>         table="Employee">
>>>>>     <field-descriptor
>>>>>         name="oid"
>>>>>         column="userId"
>>>>>         jdbc-type="INTEGER"
>>>>>         primarykey="true"/>
>>>>>      <field-descriptor
>>>>>         name="startedWork"
>>>>>         column="startedWork"
>>>>>         jdbc-type="DATE"/>
>>>>>          etc...
>>>>>      <reference-descriptor
>>>>>         name="this"
>>>>>         class-ref="com.company.entity.User"
>>>>>         auto-retrieve="true" auto-update="true" auto-delete="true">
>>>>>         <foreignkey field-ref="oid"/>
>>>>>      </reference-descriptor>
>>>>>   </class-descriptor>
>>>>>
>>>>> when I try to do a search in "User" type, (expecting an Employee to 
>>>>> be returned), the moment I call broker.getCollectionByQuery(query), 
>>>>> I get the following stack trace:
>>>>>
>>>>> Caused by: java.lang.NullPointerException
>>>>>    at 
>>>>> org.apache.ojb.broker.metadata.ClassDescriptor.getObjectReferenceDescriptorByName(Unknown 
>>>>> Source)
>>>>>    at 
>>>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.getFieldDescriptor(Unknown 
>>>>> Source)
>>>>>    at 
>>>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.getColName(Unknown 
>>>>> Source)
>>>>>    at 
>>>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendColName(Unknown 
>>>>> Source)
>>>>>    at 
>>>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendSelectionCriteria(Unknown 
>>>>> Source)
>>>>>    at 
>>>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendCriteria(Unknown 
>>>>> Source)
>>>>>    at 
>>>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendSQLClause(Unknown 
>>>>> Source)
>>>>>    at 
>>>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.asSQLStatement(Unknown 
>>>>> Source)
>>>>>    at 
>>>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendClause(Unknown 
>>>>> Source)
>>>>>    at 
>>>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendWhereClause(Unknown 
>>>>> Source)
>>>>>    at 
>>>>> org.apache.ojb.broker.accesslayer.sql.SqlSelectStatement.getStatement(Unknown 
>>>>> Source)
>>>>>    at 
>>>>> org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl.getPreparedSelectStatement(Unknown 
>>>>> Source)
>>>>>    at 
>>>>> org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeQuery(Unknown 
>>>>> Source)
>>>>>    at org.apache.ojb.broker.accesslayer.RsIterator.<init>(Unknown 
>>>>> Source)
>>>>>    at 
>>>>> org.apache.ojb.broker.core.RsIteratorFactoryImpl.createRsIterator(Unknown 
>>>>> Source)
>>>>>    at 
>>>>> org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery(Unknown 
>>>>> Source)
>>>>>    at 
>>>>> org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery(Unknown 
>>>>> Source)
>>>>>    at 
>>>>> org.apache.ojb.broker.core.PersistenceBrokerImpl.getIteratorFromQuery(Unknown 
>>>>> Source)
>>>>>    at 
>>>>> org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Unknown 
>>>>> Source)
>>>>>    ... 42 more
>>>>
>>>>
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 


Re: trying to implement inheritance-but failing!

Posted by Raymond Barlow <rb...@raymanoz.com>.
Hi again,

Well, just to keep you up to date (if anyone is interested), I added the 
FK Id fields back into my classes, removed the anonymous field access, 
and I still get the same stack trace and exception.

It is definately something to do with the use of the "this" reference 
descriptor. I guess now my only choice left is to integrate the source 
code into my project, and step debug the code (yay!) :)

Thomas (if you're reading this!): Have you ever successfully done a 
query/search to retreive a class which has implementes vertical 
inheritance? (Like I've said before, persistence works beautifully, 
retrieval doesn't.)

Regards,
Raymond Barlow

Thomas Mahler wrote:

> Hi Raymond,
>
> There is currently some docuemnation on using anonymous fields for 
> mapping references avaliable at:
> http://cvs.apache.org/viewcvs/db-ojb/xdocs/howto-use-anonymous-keys.xml?rev=HEAD&content-type=text/vnd.viewcvs-markup.
>
> Unfortunately there is currently no documentation or sample code for 
> vertical inheritance. The only we have is the sample given by Tine on 
> the user list some time ago.
>
> I hope we will have some docu on this feature out soon.
>
> cheers,
> Thomas
>
> Raymond Barlow wrote:
>
>> OK, further to this, if I remove the "this" reference (shown below) 
>> descriptor from Employee mapping, I can query on Employee OK (but, of 
>> course, I cannot see any of the User fields). Have I mapped Employee 
>> correctly?? Has anyone else been successful in implementing vertical 
>> inheritance? Can someone please point me to some documentation, give 
>> me an example, or drop me a few more hints on how to get virtical 
>> inheritance working using a reference-descriptor of "this"? :)
>>
>> Regards,
>> Raymond Barlow
>>
>> removed this:
>>      <reference-descriptor
>>         name="this"
>>         class-ref="com.company.entity.User"
>>         auto-retrieve="true" auto-update="true" auto-delete="true">
>>         <foreignkey field-ref="oid"/>
>>      </reference-descriptor>
>>
>> Raymond Barlow wrote:
>>
>>> Hi again,
>>>
>>> Some further tests, and I've found out:
>>> * If I remove the extent-class elements, I can query on User, and 
>>> return an object OK
>>> * (still with no extent-class), If I query on Employee directly, 
>>> same results (ie. exception, same stack trace).
>>>
>>> This makes me think that I've defined my mapping incorrectly. But, I 
>>> can still create new Empoyee objects and persist them OK. I don't 
>>> really know the internals of OJB, but from the stack trace, it looks 
>>> like it is trying to get a field reference, or a class reference, 
>>> and failing (with NullPointer). Could it have something to do with 
>>> the anonymous fields that I've created in my mapping? (I didn't 
>>> include that part in the earlier post).
>>>
>>> -Raymond Barlow
>>>
>>> Raymond Barlow wrote:
>>>
>>>> Hi All,
>>>>
>>>> After recently reading about being able to perform vertical 
>>>> inheritance with the use of "this" in the reference-descriptor, 
>>>> I've been busy trying to get it to work, but so far have had no 
>>>> luck :(
>>>>
>>>> I think that maybe I've just misinterpreted something, or 
>>>> misunderstood one of the pas emails. But anyway, following is how 
>>>> I've done it (unsuccessfully). Any help appreciated:
>>>>
>>>> Classes:
>>>>
>>>> public class Entity
>>>> {
>>>>    Integer oid;
>>>> }
>>>>
>>>> public class User extends Entity
>>>> {
>>>>    String userName;
>>>>    String password;
>>>>      etc...
>>>> }
>>>>
>>>> public class Employee extends User
>>>> {
>>>>    Date startedWork;
>>>>       etc...
>>>> }
>>>>
>>>> repository_user.xml:
>>>>
>>>>   <class-descriptor
>>>>         class="com.company.entity.User"
>>>>         table="User">
>>>>      <extent-class class-ref="com.company.entity.Employee"/>
>>>>      <field-descriptor
>>>>         name="oid"
>>>>         column="userId"
>>>>         jdbc-type="INTEGER"
>>>>         primarykey="true"
>>>>         autoincrement="true"/>
>>>>      <field-descriptor
>>>>         name="userName"
>>>>         column="userName"
>>>>         jdbc-type="VARCHAR"/>
>>>>      <field-descriptor
>>>>         name="password"
>>>>         column="password"
>>>>         jdbc-type="VARCHAR"/>
>>>>        etc...        </class-descriptor>
>>>>   <class-descriptor
>>>>         class="com.company.entity.Employee"
>>>>         table="Employee">
>>>>     <field-descriptor
>>>>         name="oid"
>>>>         column="userId"
>>>>         jdbc-type="INTEGER"
>>>>         primarykey="true"/>
>>>>      <field-descriptor
>>>>         name="startedWork"
>>>>         column="startedWork"
>>>>         jdbc-type="DATE"/>
>>>>          etc...
>>>>      <reference-descriptor
>>>>         name="this"
>>>>         class-ref="com.company.entity.User"
>>>>         auto-retrieve="true" auto-update="true" auto-delete="true">
>>>>         <foreignkey field-ref="oid"/>
>>>>      </reference-descriptor>
>>>>   </class-descriptor>
>>>>
>>>> when I try to do a search in "User" type, (expecting an Employee to 
>>>> be returned), the moment I call broker.getCollectionByQuery(query), 
>>>> I get the following stack trace:
>>>>
>>>> Caused by: java.lang.NullPointerException
>>>>    at 
>>>> org.apache.ojb.broker.metadata.ClassDescriptor.getObjectReferenceDescriptorByName(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.getFieldDescriptor(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.getColName(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendColName(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendSelectionCriteria(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendCriteria(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendSQLClause(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.asSQLStatement(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendClause(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendWhereClause(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.accesslayer.sql.SqlSelectStatement.getStatement(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl.getPreparedSelectStatement(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeQuery(Unknown 
>>>> Source)
>>>>    at org.apache.ojb.broker.accesslayer.RsIterator.<init>(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.core.RsIteratorFactoryImpl.createRsIterator(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.core.PersistenceBrokerImpl.getIteratorFromQuery(Unknown 
>>>> Source)
>>>>    at 
>>>> org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Unknown 
>>>> Source)
>>>>    ... 42 more
>>>



Re: trying to implement inheritance-but failing!

Posted by Thomas Mahler <th...@web.de>.
Hi Raymond,

There is currently some docuemnation on using anonymous fields for 
mapping references avaliable at:
http://cvs.apache.org/viewcvs/db-ojb/xdocs/howto-use-anonymous-keys.xml?rev=HEAD&content-type=text/vnd.viewcvs-markup.

Unfortunately there is currently no documentation or sample code for 
vertical inheritance. The only we have is the sample given by Tine on 
the user list some time ago.

I hope we will have some docu on this feature out soon.

cheers,
Thomas

Raymond Barlow wrote:
> OK, further to this, if I remove the "this" reference (shown below) 
> descriptor from Employee mapping, I can query on Employee OK (but, of 
> course, I cannot see any of the User fields). Have I mapped Employee 
> correctly?? Has anyone else been successful in implementing vertical 
> inheritance? Can someone please point me to some documentation, give me 
> an example, or drop me a few more hints on how to get virtical 
> inheritance working using a reference-descriptor of "this"? :)
> 
> Regards,
> Raymond Barlow
> 
> removed this:
>      <reference-descriptor
>         name="this"
>         class-ref="com.company.entity.User"
>         auto-retrieve="true" auto-update="true" auto-delete="true">
>         <foreignkey field-ref="oid"/>
>      </reference-descriptor>
> 
> Raymond Barlow wrote:
> 
>> Hi again,
>>
>> Some further tests, and I've found out:
>> * If I remove the extent-class elements, I can query on User, and 
>> return an object OK
>> * (still with no extent-class), If I query on Employee directly, same 
>> results (ie. exception, same stack trace).
>>
>> This makes me think that I've defined my mapping incorrectly. But, I 
>> can still create new Empoyee objects and persist them OK. I don't 
>> really know the internals of OJB, but from the stack trace, it looks 
>> like it is trying to get a field reference, or a class reference, and 
>> failing (with NullPointer). Could it have something to do with the 
>> anonymous fields that I've created in my mapping? (I didn't include 
>> that part in the earlier post).
>>
>> -Raymond Barlow
>>
>> Raymond Barlow wrote:
>>
>>> Hi All,
>>>
>>> After recently reading about being able to perform vertical 
>>> inheritance with the use of "this" in the reference-descriptor, I've 
>>> been busy trying to get it to work, but so far have had no luck :(
>>>
>>> I think that maybe I've just misinterpreted something, or 
>>> misunderstood one of the pas emails. But anyway, following is how 
>>> I've done it (unsuccessfully). Any help appreciated:
>>>
>>> Classes:
>>>
>>> public class Entity
>>> {
>>>    Integer oid;
>>> }
>>>
>>> public class User extends Entity
>>> {
>>>    String userName;
>>>    String password;
>>>      etc...
>>> }
>>>
>>> public class Employee extends User
>>> {
>>>    Date startedWork;
>>>       etc...
>>> }
>>>
>>> repository_user.xml:
>>>
>>>   <class-descriptor
>>>         class="com.company.entity.User"
>>>         table="User">
>>>      <extent-class class-ref="com.company.entity.Employee"/>
>>>      <field-descriptor
>>>         name="oid"
>>>         column="userId"
>>>         jdbc-type="INTEGER"
>>>         primarykey="true"
>>>         autoincrement="true"/>
>>>      <field-descriptor
>>>         name="userName"
>>>         column="userName"
>>>         jdbc-type="VARCHAR"/>
>>>      <field-descriptor
>>>         name="password"
>>>         column="password"
>>>         jdbc-type="VARCHAR"/>
>>>        etc...        </class-descriptor>
>>>   <class-descriptor
>>>         class="com.company.entity.Employee"
>>>         table="Employee">
>>>     <field-descriptor
>>>         name="oid"
>>>         column="userId"
>>>         jdbc-type="INTEGER"
>>>         primarykey="true"/>
>>>      <field-descriptor
>>>         name="startedWork"
>>>         column="startedWork"
>>>         jdbc-type="DATE"/>
>>>          etc...
>>>      <reference-descriptor
>>>         name="this"
>>>         class-ref="com.company.entity.User"
>>>         auto-retrieve="true" auto-update="true" auto-delete="true">
>>>         <foreignkey field-ref="oid"/>
>>>      </reference-descriptor>
>>>   </class-descriptor>
>>>
>>> when I try to do a search in "User" type, (expecting an Employee to 
>>> be returned), the moment I call broker.getCollectionByQuery(query), I 
>>> get the following stack trace:
>>>
>>> Caused by: java.lang.NullPointerException
>>>    at 
>>> org.apache.ojb.broker.metadata.ClassDescriptor.getObjectReferenceDescriptorByName(Unknown 
>>> Source)
>>>    at 
>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.getFieldDescriptor(Unknown 
>>> Source)
>>>    at 
>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.getColName(Unknown 
>>> Source)
>>>    at 
>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendColName(Unknown 
>>> Source)
>>>    at 
>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendSelectionCriteria(Unknown 
>>> Source)
>>>    at 
>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendCriteria(Unknown 
>>> Source)
>>>    at 
>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendSQLClause(Unknown 
>>> Source)
>>>    at 
>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.asSQLStatement(Unknown 
>>> Source)
>>>    at 
>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendClause(Unknown 
>>> Source)
>>>    at 
>>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendWhereClause(Unknown 
>>> Source)
>>>    at 
>>> org.apache.ojb.broker.accesslayer.sql.SqlSelectStatement.getStatement(Unknown 
>>> Source)
>>>    at 
>>> org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl.getPreparedSelectStatement(Unknown 
>>> Source)
>>>    at 
>>> org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeQuery(Unknown 
>>> Source)
>>>    at org.apache.ojb.broker.accesslayer.RsIterator.<init>(Unknown 
>>> Source)
>>>    at 
>>> org.apache.ojb.broker.core.RsIteratorFactoryImpl.createRsIterator(Unknown 
>>> Source)
>>>    at 
>>> org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery(Unknown 
>>> Source)
>>>    at 
>>> org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery(Unknown 
>>> Source)
>>>    at 
>>> org.apache.ojb.broker.core.PersistenceBrokerImpl.getIteratorFromQuery(Unknown 
>>> Source)
>>>    at 
>>> org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Unknown 
>>> Source)
>>>    ... 42 more
>>>
>>> Any ideas?
>>>
>>> -- 
>>> Regards,
>>> Raymond Barlow
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>>
>>
> 


Re: trying to implement inheritance-but failing!

Posted by Raymond Barlow <rb...@raymanoz.com>.
OK, further to this, if I remove the "this" reference (shown below) 
descriptor from Employee mapping, I can query on Employee OK (but, of 
course, I cannot see any of the User fields). Have I mapped Employee 
correctly?? Has anyone else been successful in implementing vertical 
inheritance? Can someone please point me to some documentation, give me 
an example, or drop me a few more hints on how to get virtical 
inheritance working using a reference-descriptor of "this"? :)

Regards,
Raymond Barlow

removed this:
      <reference-descriptor
         name="this"
         class-ref="com.company.entity.User"
         auto-retrieve="true" auto-update="true" auto-delete="true">
         <foreignkey field-ref="oid"/>
      </reference-descriptor>

Raymond Barlow wrote:

> Hi again,
>
> Some further tests, and I've found out:
> * If I remove the extent-class elements, I can query on User, and 
> return an object OK
> * (still with no extent-class), If I query on Employee directly, same 
> results (ie. exception, same stack trace).
>
> This makes me think that I've defined my mapping incorrectly. But, I 
> can still create new Empoyee objects and persist them OK. I don't 
> really know the internals of OJB, but from the stack trace, it looks 
> like it is trying to get a field reference, or a class reference, and 
> failing (with NullPointer). Could it have something to do with the 
> anonymous fields that I've created in my mapping? (I didn't include 
> that part in the earlier post).
>
> -Raymond Barlow
>
> Raymond Barlow wrote:
>
>> Hi All,
>>
>> After recently reading about being able to perform vertical 
>> inheritance with the use of "this" in the reference-descriptor, I've 
>> been busy trying to get it to work, but so far have had no luck :(
>>
>> I think that maybe I've just misinterpreted something, or 
>> misunderstood one of the pas emails. But anyway, following is how 
>> I've done it (unsuccessfully). Any help appreciated:
>>
>> Classes:
>>
>> public class Entity
>> {
>>    Integer oid;
>> }
>>
>> public class User extends Entity
>> {
>>    String userName;
>>    String password;
>>      etc...
>> }
>>
>> public class Employee extends User
>> {
>>    Date startedWork;
>>       etc...
>> }
>>
>> repository_user.xml:
>>
>>   <class-descriptor
>>         class="com.company.entity.User"
>>         table="User">
>>      <extent-class class-ref="com.company.entity.Employee"/>
>>      <field-descriptor
>>         name="oid"
>>         column="userId"
>>         jdbc-type="INTEGER"
>>         primarykey="true"
>>         autoincrement="true"/>
>>      <field-descriptor
>>         name="userName"
>>         column="userName"
>>         jdbc-type="VARCHAR"/>
>>      <field-descriptor
>>         name="password"
>>         column="password"
>>         jdbc-type="VARCHAR"/>
>>        etc...        </class-descriptor>
>>   <class-descriptor
>>         class="com.company.entity.Employee"
>>         table="Employee">
>>     <field-descriptor
>>         name="oid"
>>         column="userId"
>>         jdbc-type="INTEGER"
>>         primarykey="true"/>
>>      <field-descriptor
>>         name="startedWork"
>>         column="startedWork"
>>         jdbc-type="DATE"/>
>>          etc...
>>      <reference-descriptor
>>         name="this"
>>         class-ref="com.company.entity.User"
>>         auto-retrieve="true" auto-update="true" auto-delete="true">
>>         <foreignkey field-ref="oid"/>
>>      </reference-descriptor>
>>   </class-descriptor>
>>
>> when I try to do a search in "User" type, (expecting an Employee to 
>> be returned), the moment I call broker.getCollectionByQuery(query), I 
>> get the following stack trace:
>>
>> Caused by: java.lang.NullPointerException
>>    at 
>> org.apache.ojb.broker.metadata.ClassDescriptor.getObjectReferenceDescriptorByName(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.getFieldDescriptor(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.getColName(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendColName(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendSelectionCriteria(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendCriteria(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendSQLClause(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.asSQLStatement(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendClause(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendWhereClause(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.accesslayer.sql.SqlSelectStatement.getStatement(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl.getPreparedSelectStatement(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeQuery(Unknown 
>> Source)
>>    at org.apache.ojb.broker.accesslayer.RsIterator.<init>(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.core.RsIteratorFactoryImpl.createRsIterator(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.core.PersistenceBrokerImpl.getIteratorFromQuery(Unknown 
>> Source)
>>    at 
>> org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Unknown 
>> Source)
>>    ... 42 more
>>
>> Any ideas?
>>
>> -- 
>> Regards,
>> Raymond Barlow
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>

-- 
Regards,
Raymond Barlow
--------------------------------------
(For contact details, please email me)



Re: trying to implement inheritance-but failing!

Posted by Raymond Barlow <rb...@raymanoz.com>.
Hi again,

Some further tests, and I've found out:
* If I remove the extent-class elements, I can query on User, and return 
an object OK
* (still with no extent-class), If I query on Employee directly, same 
results (ie. exception, same stack trace).

This makes me think that I've defined my mapping incorrectly. But, I can 
still create new Empoyee objects and persist them OK. I don't really 
know the internals of OJB, but from the stack trace, it looks like it is 
trying to get a field reference, or a class reference, and failing (with 
NullPointer). Could it have something to do with the anonymous fields 
that I've created in my mapping? (I didn't include that part in the 
earlier post).

-Raymond Barlow

Raymond Barlow wrote:

> Hi All,
>
> After recently reading about being able to perform vertical 
> inheritance with the use of "this" in the reference-descriptor, I've 
> been busy trying to get it to work, but so far have had no luck :(
>
> I think that maybe I've just misinterpreted something, or 
> misunderstood one of the pas emails. But anyway, following is how I've 
> done it (unsuccessfully). Any help appreciated:
>
> Classes:
>
> public class Entity
> {
>    Integer oid;
> }
>
> public class User extends Entity
> {
>    String userName;
>    String password;
>      etc...
> }
>
> public class Employee extends User
> {
>    Date startedWork;
>       etc...
> }
>
> repository_user.xml:
>
>   <class-descriptor
>         class="com.company.entity.User"
>         table="User">
>      <extent-class class-ref="com.company.entity.Employee"/>
>      <field-descriptor
>         name="oid"
>         column="userId"
>         jdbc-type="INTEGER"
>         primarykey="true"
>         autoincrement="true"/>
>      <field-descriptor
>         name="userName"
>         column="userName"
>         jdbc-type="VARCHAR"/>
>      <field-descriptor
>         name="password"
>         column="password"
>         jdbc-type="VARCHAR"/>
>        etc...        </class-descriptor>
>   <class-descriptor
>         class="com.company.entity.Employee"
>         table="Employee">
>     <field-descriptor
>         name="oid"
>         column="userId"
>         jdbc-type="INTEGER"
>         primarykey="true"/>
>      <field-descriptor
>         name="startedWork"
>         column="startedWork"
>         jdbc-type="DATE"/>
>          etc...
>      <reference-descriptor
>         name="this"
>         class-ref="com.company.entity.User"
>         auto-retrieve="true" auto-update="true" auto-delete="true">
>         <foreignkey field-ref="oid"/>
>      </reference-descriptor>
>   </class-descriptor>
>
> when I try to do a search in "User" type, (expecting an Employee to be 
> returned), the moment I call broker.getCollectionByQuery(query), I get 
> the following stack trace:
>
> Caused by: java.lang.NullPointerException
>    at 
> org.apache.ojb.broker.metadata.ClassDescriptor.getObjectReferenceDescriptorByName(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.getFieldDescriptor(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.getColName(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendColName(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendSelectionCriteria(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendCriteria(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendSQLClause(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.asSQLStatement(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendClause(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlQueryStatement.appendWhereClause(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlSelectStatement.getStatement(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl.getPreparedSelectStatement(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeQuery(Unknown 
> Source)
>    at org.apache.ojb.broker.accesslayer.RsIterator.<init>(Unknown Source)
>    at 
> org.apache.ojb.broker.core.RsIteratorFactoryImpl.createRsIterator(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.core.PersistenceBrokerImpl.getRsIteratorFromQuery(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.core.PersistenceBrokerImpl.getIteratorFromQuery(Unknown 
> Source)
>    at 
> org.apache.ojb.broker.core.PersistenceBrokerImpl.getCollectionByQuery(Unknown 
> Source)
>    ... 42 more
>
> Any ideas?
>
> -- 
> Regards,
> Raymond Barlow
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>

-- 
Regards,
Raymond Barlow
--------------------------------------
(For contact details, please email me)