Yeah -- thanks for the suggestion -- I actually thought about the view option, but was curious if it could be expressed within the mapping itself.
Playing around with these mappings this morning, I realized that I hadn't really set up the class relationships correctly. A revised set of mappings:
Code:
<hibernate-mapping>
<class
entity-name="tier1"
table="tier1"
node="tier1">
<id name="tier1_id" type="long"/>
<property name="tier1_desc" type="string"/>
</class>
<class
entity-name="tier2"
table="tier2"
node="tier2">
<composite-id>
<key-property name="tier2_id" type="long"/>
<key-property name="tier1_id" type="long"/>
</composite-id>
<property name="id" type="long" insert="false" update="false"/>
<property name="tier2_desc" type="string"/>
<many-to-one name="tier1" entity-name="tier1" column="tier1_id" update="false" insert="false"/>
</class>
<class
entity-name="tier3"
table="tier3"
node="tier3">
<composite-id>
<key-property name="tier3_id" type="long"/>
<key-property name="tier2_id" type="long"/>
<key-property name="tier1_id" type="long"/>
</composite-id>
<property name="id" type="long" insert="false" update="false"/>
<property name="tier3_desc" type="string"/>
<many-to-one name="tier2" entity-name="tier1" update="false" insert="false">
<column name="tier2_id"/>
<column name="tier1_id"/>
</many-to-one>
</class>
</hibernate-mapping>
The above is a more accurate representation of the relationship between tier1, tier2 and tier3. So the first problem is the join issue, where I wanted a nice way to express the join in the mapping. The <many-to-one> references in tier2 and tier3 sort of achieve this, in that I can now access the information I need through the many-to-one relationship. I could alternatively modify the classes slightly to support views for tier2 and tier3, which would also work.
However, now that I am using composite-id's, I no longer have my nice identity column "id" expressed as a <generator>. I still need that identity column, so it is now represented as a <property>, but I do not seem to have a way of expressing (in a mapping) that it is an identity column, but not a primary key.
Right now, I am generating the tables using SQL, where the "id" column is created as:
Code:
[id] [int] IDENTITY (1, 1) NOT NULL
but I do not see a way of expressing this in a mapping when "id" is not a primary key on the table.
Any suggestions are welcome.