Hi,
I am facing quite interresting scenario, I think...
I want to have a one-to-many relationship for my bag. But I want to use a two-column foreing key referencing two columns that are NOT PK. The bag is inverse because child elements get inserted separately from their parent and the association is ment for querying only - to get parent (Telegram) with its accompanying elements (Acknowledgement(s))
My solution consists from tables:
Code:
TELEGRAM
ID PK
TASK_ID
CHANNEL
Code:
ACK
ID PK
TASK_ID
CHANNEL
and mapping that looks somehow like
Code:
<class name="Telegram">
<id name="ID" column="`ID`">
<generator class="native" />
</id>
<property name="TaskId" column="`TASK_ID`" not-null="false" update="false" />
<property name="Channel" column="`CHANNEL`" update="false" />
<bag name="AcknowledgementList" generic="true" inverse="true">
<key foreign-key="TaskId" property-ref="TaskId">
<column name="`TASK_ID`" />
</key>
<one-to-many class="Acknowledgement" />
</bag>
</class>
NOTE: for now I have a single column. Need two - additionally Channel column.
and mapped classes:
Code:
<class name="Acknowledgement" table="`TTL_ACK`">
<id name="ID" column="`ID`">
<generator class="native" />
</id>
<property name="TaskId" column="`TASK_ID`" not-null="true" update="false" />
<property name="Channel" column="`CHANNEL`" not-null="false" update="false" />
</class>
REMARK: Maybe there's a way to prevent persisting a bag during Telegram updates - this also would solve my problems which are related to existing of shared references (of acknowledgments) among several telegrams - due to invalid select...
I know that it is not much pretty but I have quite complex environment I have to operate with...
Most things have been cut from entities for clearance purpose.
TIA