Hi.

My database schema has quite some references and in order to avoid
loading always a great part of the wohle object graph I would like to
get some of the often used detail data directly in the entity without
denormalizing the schema.

Two concrete examples: In the following mappings the class
'Waggongroup' should be extended with the name of the associated
MetaTrain (Waggongroup.Schedule.MetaTrain.Name). The other detail I'm
interested in is the StartingStation of the first associated
NetworkSection in the Routing list of the Waggongroup and the
Destination of the last associated NetworkSection in the Routing list.

Here is the mapping:

-----<Mappings>---------------------------------------------

<class name="Waggongroup">
  <id .../>
  <version .../>
  
  <many-to-one name="Schedule" class="Schedule" not-null="true"/>
  
  <list name="Routing">
    <key .../>
    <index column="route_order"/>
    <many-to-many class="NetworkSection"/>
  </list>
  ...
</class>

<class name="Schedule">
  <id .../>
  <version .../>

  <many-to-one name="MetaTrain" class="MetaTrain" not-null="true"/>
  ...
</class>

<class name="MetaTrain">
  <id .../>
  <version .../>

  <property name="Name" type="String" not-null="true" unique="true"/>
  ...
</class>

<class name="NetworkSection">
  <id .../>
  <version .../>

  <many-to-one name="StartingStation" class="Location" not-null="true" 
unique-key="UQ_Track"/>
  <many-to-one name="Destination" class="Location" not-null="true" 
unique-key="UQ_Track"/>
  ...
</class>

<class name="Location">
  <id .../>
  <version .../>

  <property name="Name" type="String" not-null="true"/>
  <property name="Mnemonic" type="String" not-null="true" unique="true"/>
  ...
</class>

-----</Mappings>--------------------------------------------

My first attempt to solve at least the easier of the two
denomalizations is to use a property with a formula, something like
the following in the Waggongroup:

  <property name="MetaTrainName" formula="(SELECT ....)"/>

This kind of works. The problem is that I need to support SqLite (for
testing purposes), MS SQL Server, and Oracle. All users of Oracle have
a default schema that is different than the schema where the tables
live so all objects have to be fully qualified with the schema
name. On the other hand MS-SQL and SqLite don't have this problem and
both don't use schemas. Is there any way to use formula in such a way
that would work with both cases? Or even better: Would it be possible
to use HQL for the formula (or is such a support planned for the
(near) future)?

Has anybody other ideas how to achive the denormalization in the
domain model without denormalizing the database?

-- 
Until the next mail...,
Stefan.

Attachment: pgpIUXvYfFBT7.pgp
Description: PGP signature

Reply via email to