-->
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.  [ 3 posts ] 
Author Message
 Post subject: Mapping a subclass using id/status combination.
PostPosted: Thu Oct 06, 2005 1:35 pm 
Newbie

Joined: Thu Oct 06, 2005 12:30 pm
Posts: 10
I've looked all over and can't find this situation described. I need some advice in mapping a subclass to an existing (and unchangeable) data model. A base level abstract class "Participant" is mapped to a single table which contains a generalized set of properties. Subclasses of Participant may or may not have an additional table associated to them. One subclass that does, "CorporateLocation", involves joining a record from the "corporateLocation" table. However, for a given participantId in this table, one or more records may exists, but only one with a status of 'A' (active). The other non-active records provide a temporal log of previous setups for that participant.

Here's the database schema:

Code:
-----------------------------------
participant
-----------------------------------
participantId | int(10)       | PRI
name          | varchar(100)  | MUL
address       | varchar(100)  |
city          | varchar(20)   |
state         | varchar(10)   |
country       | varchar(20)   |
zip           | varchar(20)   |
type          | int(11)       |
-----------------------------------

-----------------------------------------
corporateLocation
-----------------------------------------
corporateLocationId | int(10)       | PRI
participantId       | int(10)       | MUL
setupCode           | varchar(20)   |
status              | char(1)       |
-----------------------------------------


I'm having trouble mapping this subclass so that the "status = 'A'" condition is used in the join.

Here's what I have thus far:

Code:
<hibernate-mapping>

  <class name="com.foo.domain.model.Participant" table="participant"
    abstract="true" lazy="false"
    discriminator-value="-1">

    <id name="id" type="java.lang.Long" column="participantId" unsaved-value="null">
      <generator class="native" />
    </id>
   
    <discriminator column="type" type="java.lang.Integer" not-null="true"/>
    <property name="type" type="java.lang.Integer" not-null="true" insert="false" update="false"/>
    <property name="name" type="java.lang.String" column="name" not-null="true" unique="true" length="100"/>
    <component name="address" class="com.foo.domain.model.Address">
      <property name="address1" type="java.lang.String" column="address" length="100"/>
      <property name="city" type="java.lang.String" column="city" length="20"/>
      <property name="state" type="java.lang.String" column="state" length="10"/>
      <property name="country" type="java.lang.String" column="country" length="20"/>
      <property name="zip" type="java.lang.String" column="zip" length="20"/>
    </component>

    <subclass name="com.foo.domain.model.RegionalOffice" extends="com.foo.domain.model.Participant" discriminator-value="104"/>
    <subclass name="com.foo.domain.model.DistrictOffice" extends="com.foo.domain.model.Participant" discriminator-value="103"/>

    <subclass name="com.foo.domain.model.CorporateLocation" extends="com.foo.domain.model.Participant" discriminator-value="106">
      <join table="corporateLocation">
        <key column="participantId"/>
        <property name="setupCode" type="java.lang.String"/>
        <property name="status" type="java.lang.String"/>
      </join>
    </subclass>
   
  </class>
 
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 07, 2005 8:30 am 
Newbie

Joined: Thu Oct 06, 2005 12:30 pm
Posts: 10
Using Hibernate 3.0


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 11, 2005 5:22 pm 
Newbie

Joined: Thu Oct 06, 2005 12:30 pm
Posts: 10
Instead of hibernate performing the join simply on the participantId:

Code:
select
  corporatel0_.participantId as particip1_,
  corporatel0_.type as type2_,
  corporatel0_.name as name2_,
  corporatel0_.address as address2_,
  corporatel0_.city as city2_,
  corporatel0_.state as state2_,
  corporatel0_.country as country2_,
  corporatel0_.zip as zip2_,
  corporatel0_1_.status as status3_
from
  participant corporatel0_ inner join corporatelocation corporatel0_1_
  on corporatel0_.participantId=corporatel0_1_.participantId
where
  corporatel0_.type=106
  and corporatel0_.participantId=?


I would like an additional "status = A" criteria added to join like:

Code:
select
  corporatel0_.participantId as particip1_,
  corporatel0_.type as type2_,
  corporatel0_.name as name2_,
  corporatel0_.address as address2_,
  corporatel0_.city as city2_,
  corporatel0_.state as state2_,
  corporatel0_.country as country2_,
  corporatel0_.zip as zip2_,
  corporatel0_1_.status as status3_
from
  participant corporatel0_ inner join corporatelocation corporatel0_1_
  on corporatel0_.participantId=corporatel0_1_.participantId
  and corporatel0_1_.status='A'
where
  corporatel0_.type=106
  and corporatel0_.participantId=?


Any help appreciated.


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

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.