-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Inheritance and primary keys
PostPosted: Mon Sep 13, 2004 8:56 am 
Newbie

Joined: Fri Aug 20, 2004 9:25 am
Posts: 9
The database I have to work with has defined primary keys on virtually every table, but ideally I would like to implement some inheritance at the object layer. e.g. The database defines an asset with a primary key, a contract which is an asset has it's own primary key and a clientContract which is an contract has it's own primary key.

Asset
assetId(PK)

Contract
contractId(PK)
assetId - join key

ClientContract
clientContractId(PK)
contractId - join key

I can create an inheritance mapping via a subclass(join) in V3.0 on assetId and that all works. Unfortunately I cannot then subclass ClientContract, a class gets created but no values are populated, I assume this is because contractId is not available for the join. Is there anyway round this or would I need to get the data model changed.

Thanks,

John


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 13, 2004 11:34 am 
Newbie

Joined: Fri Aug 20, 2004 9:25 am
Posts: 9
Attached is the mapping file.

If I run the query - from asset as a where a.assetId = 21 I get returned a ClientContract but none of the client contract details are populated. The contract details and asset details are present and the contractNumber is set as 1012
If I run the query - from ClientContract as cc where cc.contractNumber= 1012 I get nothing found.


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">


<hibernate-mapping package="com.inmezzo.titan">

<class name="Asset" table="asset">
<id name="assetId" column="asset_id" type="java.lang.Integer">
<generator class="native" />
</id>

<discriminator column="case_of_asset_type_id" formula="case_of_asset_type_id"/>

<!-- Mapping for AssetReferenceCode association. -->
<set name="referenceCodes" cascade="none" lazy="true" inverse="true">
<key>
<column name="for_asset_id" not-null="true" />
</key>
<one-to-many class="AssetReferenceCode" />
</set>

<subclass name="Contract" discriminator-value="8">

<join table="contract">
<key column="is_asset_id"></key>
<property name="contractNumber" column="contract_number"
type="java.lang.String" not-null="true" />

<property name="contractId" column="contract_id" type="java.lang.Integer" not-null="true" />

</join>

<subclass name="ClientContract" discriminator-value="12">


<!-- Mapping for ContractServiceFee association. -->
<set name="contractServiceFees"
cascade="none"
lazy="true"
inverse="true">
<key>
<column name="for_client_contract_id" not-null="true"/>
</key>
<one-to-many class="ContractServiceFee"/>
</set>

<join table="client_contract">
<key column="is_contract_id"></key>
<property name="commencementDate" column="commencement_date" type="java.util.Date" />
<property name="greenSortingIndicator" column="green_sorting_indicator" type="java.lang.String" />
<property name="contractSetupFee" column="contract_setup_fee" type="java.lang.Double" />
<property name="clientContractId" column="client_contract_id" type="java.lang.Integer" />

</join>

</subclass>
</subclass>


<subclass name="PhysicalAsset">

<!-- Mapping for AssetFeatureValue association. -->
<set name="assetFeatureValues" cascade="none" lazy="true"
inverse="true">
<key>
<column name="of_physical_asset_id" not-null="true" />
</key>
<one-to-many class="AssetFeatureValue" />
</set>

<join table="physical_asset" >
<key column="is_asset_id"></key>
<!--
<property name="physicalAssetNumber" column="physical_asset_number" type="java.lang.String" not-null="true" />
-->
<property name="physicalAssetNumber"
column="physical_asset_number" type="java.lang.String"
not-null="true">
<meta attribute="finder-method">findByName</meta>
</property>

<many-to-one name="modelSpecification"
column="of_model_specification_id" class="ModelSpecification" />

<many-to-one name="assetSpecification"
column="case_of_asset_specification_id" class="AssetSpecification" />

<many-to-one name="equipmentType"
column="case_of_equipment_type_id" class="EquipmentType" />

<!--
<many-to-one name="asset" column="is_asset_id" class="Asset" not-null="true" />
-->

</join>

<subclass name="EquipmentItem" discriminator-value="1">
</subclass>
<subclass name="Bundle" discriminator-value="2"></subclass>
<subclass name="Parcel" discriminator-value="3">
<!-- Mapping for CollectionRequest association. -->
<set name="collectionRequest" cascade="none" lazy="true"
inverse="true">
<key>
<column name="for_asset_id" not-null="true" />
</key>
<one-to-many class="CollectionRequest" />
</set>
</subclass>
<subclass name="Pallet" discriminator-value="4"></subclass>
<subclass name="Transfer" discriminator-value="5">
</subclass>
<subclass name="RCYPallet" discriminator-value="6">
</subclass>
<subclass name="Container" discriminator-value="7">
</subclass>
<subclass name="Item" discriminator-value="9"></subclass>
<subclass name="PWO" discriminator-value="10"></subclass>
<subclass name="Picklist" discriminator-value="11">
</subclass>
</subclass>

</class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 13, 2004 12:40 pm 
Newbie

Joined: Fri Aug 20, 2004 9:25 am
Posts: 9
I think I'm starting to understand this. A lot of the issues I am seeing seem to be because the subclasses have different identifiers to the parent. Even the one-to-many mappings are failing. Is there a way of specifying a different identifier for the subclass or must it always be the same identifier as the parent?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.