What I desire to have happen, is for OJB to properly cast each extent into it's appropriate subclass.
I've found that I can make this happen, but I'm worried that it might not be a safe method.
I have 2 tables, assets and computers.
Every computer is an asset, but not every asset is a computer.
I use the id field as the primary key for each table and as a foreign key for the computer table.
My repository structure is below.
I'm using the persistance broker interface to make calls with both getCollectionByQuery and getObjectByQuery;
What I've found is that OJB will generally cast all extents into a base "AssetBean" unless I add a redundant anonymous key to the ComputerAssetBean repository entry.
When there is 1 case of matching id fields in Assets and Computers and I call getObjectByQuery(Asset.class, id...) the results always come back cast as an AssetBean but I can see in the debug log that OJB at some point did try to look at the Computer table.
In the same circumstances, if I instead call getCollectionByQuery(Asset.class, id...) I will get back a collection with 1 AssetBean, and 1 ComputerAssetBean, which is close enough to the desired behavior that I can work with it.
My question is: Is this a safe practice?
Is there a better way to insure than an extent of an interface is properly cast into the most appropriate implimenting sub-class?
<class-descriptor class="org.aspca.vo.Asset"> <extent-class class-ref="org.aspca.vo.AssetBean" /> <extent-class class-ref="org.aspca.vo.ComputerAssetBean" /> </class-descriptor>
<class-descriptor class="org.aspca.vo.AssetBean" table="INVENTR.ASSETS">
<extent-class class-ref="org.aspca.vo.ComputerAssetBean" />
<field-descriptor name="id" primarykey="true" nullable="false" default-fetch="true" column="ASSETID" jdbc-type="SMALLINT" autoincrement="true"
access="readonly"/>
</class-descriptor>
<class-descriptor class="org.aspca.vo.ComputerAssetBean" table="INVENTR.COMPUTERS">
<field-descriptor name="id" primarykey="true" nullable="false" default-fetch="true" column="ASSETID" jdbc-type="SMALLINT" access="readonly"/>
<field-descriptor name="assetId" primarykey="true" nullable="false" default-fetch="true" column="ASSETID" jdbc-type="SMALLINT" access="anonymous"/>
<field-descriptor name="RAM" default-fetch="true" column="RAM" jdbc-type="INTEGER"/>
<field-descriptor name="computerName" default-fetch="true" column="COMPUTERNAME" jdbc-type="CHAR"/>
<reference-descriptor name="super"
class-ref="org.aspca.vo.AssetBean"
auto-retrieve="true"
auto-update="true"
auto-delete="true"
>
<foreignkey field-ref="assetId"/>
</reference-descriptor>
</class-descriptor>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
