-->
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.  [ 2 posts ] 
Author Message
 Post subject: Question on Legacy Database Collection Mapping
PostPosted: Wed Sep 26, 2007 11:50 am 
Newbie

Joined: Wed Sep 26, 2007 11:26 am
Posts: 2
NHibernate version: 1.2.0.4000
Name and version of the database you are using: SQL Server 2000

I have a legacy SQL Server 2000 database that has some interesting link tables used for collections. An example:
Code:
______________________
| Documents            |
|______________________|
| DocId(int) *         |
| TagCollectionId(int) |
|______________________|

_______________________
| TagCollection         |
|_______________________|
| TagCollectionId* (int)|
| Order*(int)           |
| ItemId*(int)          |
|_______________________|

_________________________
| Tags                    |
|_________________________|
| ItemId*(int)            |
| Description(varchar(25) |
|_________________________|

The problem I'm having is how to map the TagCollection and Tag tables with the Documents table. I'd like to have a Document class with a Tags property, but I'm not sure if that's feasible or if I need a TagCollection class as well (I'm thinking yes because of the Order column, but I'm not sure). Further complicating things (at least for me) is the fact that the TagCollection table does not contain a DocId column, but instead the TagCollectionId from the Documents table.

Any advice on how to proceed with this type of mapping is appreciated.

Thanks,
Sean Carpenter


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 28, 2007 11:17 am 
Newbie

Joined: Wed Sep 26, 2007 11:26 am
Posts: 2
I have an update on this issue.

I was able to make this work in Hibernate 3.2.5 using property-ref attributes like this:
Documents.hbm.xml
Code:
<class name="Documents" table="Documents" schema="dbo" catalog="Hibernate">
        <id name="docId" type="string">
            <column name="DocId" />
            <generator class="assigned" />
        </id>
        <property name="tagCollectionId" type="string">
            <column name="TagCollectionID" unique="true" />
        </property>
        <set name="tags" table="TagCollection">
            <key property-ref="tagCollectionId">
                <column name="TagCollectionId" not-null="true" />
            </key>
            <many-to-many column="ItemID" class="Tags" />
        </set>
    </class>


and Tags.hbm.xml
Code:
<class name="Tags" table="Tags" schema="dbo" catalog="Hibernate">
        <id name="itemId" type="string">
            <column name="ItemID" />
            <generator class="assigned" />
        </id>
        </property>
        <property name="description" type="string">
            <column name="Description" />
        </property>
        <set name="documents" inverse="true" table="TagCollection">
            <key>
                <column name="ItemID" not-null="true" />
            </key>
            <many-to-many class="Documents" property-ref="tagCollectionId" column="TagCollectionID" />
        </set>
    </class>


The problem now is that the property-ref attribute does not exist for <key> or <many-to-many> elements in NHibernate. I'm going to look at other ways of mapping as well as what it would take to add this functionality to NHibernate (a JIRA issue already exists).

Sean Carpenter


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