Hibernate 3.2.5, MySQL 5.0.24
I'd like to further constrain the join used in a subclass beyond just the foreign key. I'm using
table per subclass to map this particular class hierarchy. I have a status field in the subclass table I'd like to check for a value of 'A'.
I have tables: participant, bank, store where banks and stores are participants (simplified below).
Code:
participant (participantId, name, type)
store (storeId, status, participantId, eid)
bank (bankId, status, participantId, dda)
The oddity in the existing data model is that the database relationship to bank (or store) from participant is one-to-many. However the conceptual relationship is a one-to-one temporal where bank.status='A'.
Code:
<hibernate-mapping>
<class name="com.domain.model.Participant" table="participant" discriminator-value="not null">
<id name="participantId" type="java.lang.Long" unsaved-value="null">
<generator class="native" />
</id>
<discriminator column="type" type="java.lang.Integer" not-null="true"/>
<property name="name" type="java.lang.String" not-null="true"/>
<subclass name="com.domain.model.Bank" discriminator-value="1">
<join table="bank" optional="true">
<key column="participantId" /><!-- ** NEED to add status='A' as well ** -->
<property name="dda" type="java.lang.String"/>
</join>
</subclass>
<subclass name="com.domain.model.Store" discriminator-value="2">
<join table="store" optional="true">
<key column="participantId" /><!-- ** NEED to add status='A' as well ** -->
<property name="eid" type="java.lang.String"/>
</join>
</subclass>
</class>
</hibernate-mapping>
I've searched the docs and using filters seemed to stand out as a possible solution although I would have to manually enable the filter for each session. In the end, they are not currently supported on subclass mappings (see HHH-2394) so I was not able to use them. If only it made sense for join to support a where-like attribute like <class> does.
Any help appreciated. Thanks in advance,