Hi Derek.

Your question is very interesting. I'm afraid that the inheritance
hierarchy that you would like to implement is not supported by Torque.
The reason is that the inheritance model supported by Torque maps all
objects in the class hierarchy to a single table. All attributes for
every class in the hierarchy are stored in the table. See
http://jakarta.apache.org/turbine/torque/inheritance-guide.html

I also had the need of a "super object" table, and spent some time
looking for the best solution. Finally, I implemented it by pure
references combined with some class-loading, but I am not happy with the
result.

My hierarchy looks something like this:

<table name="BASE_OBJECT" idMethod="idbroker">
        <column name=OBJECT_ID" required="true" primaryKey="true"
type="INTEGER"/>
        <column name=FOREIGN_ID" required="true" primaryKey="false"
type="INTEGER"/>
        <column name="JAVA_NAME" size="255" type="VARCHAR"/>    
</table>
<table name="STUDENT" idMethod="idbroker"
baseClass="com.mondao....BaseObjectHolder">
        <column name=STUDENT_ID" required="true" primaryKey="true"
type="INTEGER"/>
</table>

Then I override the save() method in Student, so that when a STUDENT
tuple is inserted, a BASE_OBJECT tuple is inserted (with the foregin_id
= student_id, java_name = com.mondao...Student) as well.

In the BaseObject class, I introduce a method BasObjectHolder
getBaseObjectHolder() that class loads an instance, and retrieves it by
the primary key.

Please keep me notified if you find a better soloution!

Regards,
Jonas

-----Ursprungligt meddelande-----
Fr�n: Gaasch, Derek [mailto:[EMAIL PROTECTED]] 
Skickat: den 2 december 2002 19:01
Till: 'Turbine Users List'
�mne: Torque Inheritance


Hello. I'm trying to figure out how to represent an object hierarchy in
my
turbine app using torque. The core need is to have each item in the
system
generate its own unique id. I'd like there to be a base 'object' table
that
uses idbroker to generate auto-incremented ids. Creating an object of a
specific type (a teacher, class, or student, for example) must insert a
row
into object and generate a unique id, and then create a row in the
appropriate corresponding subclass table (teacher, class, or student).
Of
course, I could do this myself by first creating an 'object' object,
then
use its id to initialize a subtype, but from the torque site it looks
like
what I want to do is built in. However, the docs/example has me
confused.

Below is a simple beginning of the table structure. Where should the
<inheritance> tags go? And what does the 'key' property do?


<table name="object" idMethod="idbroker">
        <column name="OBJECT_ID" required="true" primaryKey="true"
type="INTEGER"/>
</table>
<table name="student">
        <column name=OBJECT_ID" required="true" primaryKey="true"
type="INTEGER"/>
        <column name="NAME" size="255" type="VARCHAR"/>
</table>
<table name="class">
        <column name=OBJECT_ID" required="true" primaryKey="true"
type="INTEGER"/>\
        <column name="NAME" size="255" type="VARCHAR"/>
</table>
<table name="teacher">
        <column name=OBJECT_ID" required="true" primaryKey="true"
type="INTEGER"/>
        <column name="NAME" size="255" type="VARCHAR"/>
</table>


Thanks!

-d

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


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

Reply via email to