-->
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.  [ 6 posts ] 
Author Message
 Post subject: multi-table, multi-field keys and joined-subclass
PostPosted: Wed Jul 05, 2006 2:03 pm 
Beginner
Beginner

Joined: Thu Jan 12, 2006 6:32 pm
Posts: 39
Location: Austin, Tx, USA, NA, Sol 3
[b]Hibernate version:[/b] 302

[b]Problem:[/b]
I have six tables (from a Mainframe) that are related:

Org1 (contains org2 field) maps to Org2 (contains org3) maps to Org3 (contains org4) ... all the way Org6 which is the end of the chain.

As shown below, each table has a binary key (orgX and effective_date). I have created hbm.xml files for each file independently and they parse OK.

I need however, to be able to get a "complete" org hierarchy w/one select on Org1 (result = org1+org2+ ... org6) and think that a joined-subclass in each file pointing to the next would be the way to go.

I am getting "invalid mapping" on the file below but the error is generic:
[b]Caused by: org.xml.sax.SAXParseException: The content of element type "joined-subclass" must match
"(meta*,subselect?,synchronize*,key,(property|many-to-one|one-to-one|component|dynamic-component|
any|map|set|list|bag|idbag|array|primitive-array|query-list)*,joined-subclass*,loader?,sql-insert?,
sql-update?,sql-delete?)".[/b]

My guess is the error is a result of the fact that each table's PK is binary and the <composite-key> tag isn't allowed inside a <joined-subclass>. Can the <key> tab support multiple columns?

Or am I going to have to do many-to-one relationships here?

[b]Mapping documents:[/b]

<hibernate-mapping default-cascade="none" default-access="property" auto-import="true">

<class name="us.tx.state.oag.OagCommon.hbm.HbmOagOrg5Table"
table="org5">

<composite-id>
<key-property name="Org5" column="org5" type="string"/>
<key-property name="DateEffective" column="dt_eff" type="timestamp"/>
</composite-id>

<property name="Description" column="description" type="string" update="true" insert="true"/>
<property name="DateInactive" column="dt_inactive" type="timestamp" update="true" insert="true"/>
<property name="Org6" column="org6" type="string" update="true" insert="true"/>

<joined-subclass name="us.tx.state.oag.OagCommon.hbm.HbmOagOrg6Table" table="org6">
<composite-id>
<key-property name="Org6"/>
<key-property name="DateEffective"/>
</composite-id>
<property name="Description" column="description" type="string" update="true" insert="true"/>
<property name="DateInactive" column="dt_inactive" type="timestamp" update="true" insert="true"/>
<property name="ShortName" column="short_name" type="string" update="true" insert="true"/>
<property name="UpdatedWho" column="up_user" type="string" update="true" insert="true"/>
<property name="UpdatedWhen" column="up_date" type="timestamp" update="true" insert="true"/>
</joined-subclass>

<property name="ShortName" column="short_name" type="string" update="true" insert="true"/>
<property name="UpdatedWho" column="up_user" type="string" update="true" insert="true"/>
<property name="UpdatedWhen" column="up_date" type="timestamp" update="true" insert="true"/>

</class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 05, 2006 3:18 pm 
Beginner
Beginner

Joined: Tue Jun 28, 2005 2:43 pm
Posts: 29
Location: Silicon Valley
This doesn't really sound like a subclass situation. If the tables in the chain use the same primary key all the way down, then you might be able to treat it that way, but like I said, from what you've given, it really doesn't sound like it.

When you say "Org1 (contains org2 field)", etc. I am assuming you mean it contains a foreign key to the Org2 table, is that correct? And what is the nature of this relationship, one-to-one or many-to-one?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 05, 2006 3:23 pm 
Beginner
Beginner

Joined: Thu Jan 12, 2006 6:32 pm
Posts: 39
Location: Austin, Tx, USA, NA, Sol 3
All 6 tables have a PK of <orgX> and <dateEffective> and w/t exception of the last table (org6) they have a field that is a FK to the next table. So, Org1.org2 = Org2.org2; Org2.org3 = Org3.org3 and so on.

I've been told the data is one-to-many (an org1 can have multiple org2's).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 05, 2006 3:51 pm 
Beginner
Beginner

Joined: Tue Jun 28, 2005 2:43 pm
Posts: 29
Location: Silicon Valley
The one-to-many is most likely the other way around. That is, if org1 contains a foreign key reference to org2, then each org1 can refer to only one org2, but the same org2 can be referred to by mulitple org1s. The most straightforward way to do this is with a many-to-one.

One further potential problem here: if the primary key of org2 is org2.org2 + org2.dt_eff, then org1 needs both columns to make an unambiguous foreign key.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 05, 2006 4:05 pm 
Beginner
Beginner

Joined: Thu Jan 12, 2006 6:32 pm
Posts: 39
Location: Austin, Tx, USA, NA, Sol 3
Its actually many-to-one in the org1->org2->...org6 direction (I didn't build that system).

so...one-to-many's in org1 .. org5?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 05, 2006 4:20 pm 
Beginner
Beginner

Joined: Tue Jun 28, 2005 2:43 pm
Posts: 29
Location: Silicon Valley
Code:
<class name="Org1">
...
<many-to-one name="org2" column="org2" />
...
</class>


As I said, the main problem with this is that org2 has a composite primary key, while the org1.org2 column contains only part of that key. If you have existing SQL that joins a given org1 to a unique org2 (e.g. by latest effective date, or where dt_inactive is null), you can use formula="<WHERE clause>" instead of column="org2", and that might do it.[/code]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.