Hello!
I would like to map two tables as 1 to 0 or 1. Or 1 to 0 or (n) in generic case.
Let's pretend that i have next tables.
create table document (
id int pk,
foo varchar
)
create table description(
document_id int,
description_type int,
contents varchar
)
Notice that description has discriminator field. In reality several classes generated such as, Reason, Status, CoordinatedDescription etc.
I would like to link document to description (of particular type) as 1 to 0 or 1, means i do not need store empty descriptions.
Have tryed to use one-to-one association on document side, but it will produce exception, when i try delete document without description.
Code:
<class name="Document">
<id ...>
<one-to-one name="reason" class="Reason" constrained="true" cascade="all">
On the description side i would like to substitute document_id
</class>
Code:
<class name="Description">
<id name="documentId" column="document_id">
<generator class="foreign">
<param name="property">Document</param>
</generator>
</id>
<discriminator column="description_type">
<one-to-one name="document" class="Document">
<subclass name="Reason" discriminator-value="1"/>
<subclass name="Status" discriminator-value="2"/>
<subclass name="CoordinatedDiscription" discriminator-value="3"/>
...
</class>
Can somebody explain how get it to work?
Any thoughts will be highly appreciated!