-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Subclass join by Foreign Key and the value of another field
PostPosted: Tue Oct 16, 2007 12:18 pm 
Newbie

Joined: Tue Oct 16, 2007 10:48 am
Posts: 1
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,


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.