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: Collection that is joined on column != primary key?
PostPosted: Wed Sep 06, 2006 10:11 am 
Newbie

Joined: Wed Sep 06, 2006 9:39 am
Posts: 5
Location: London
Hi,

I just wanted to check that I didn't miss something in the manual - is it possible to map a collection on a table where the join constraint is not the primary key?

My attempts just got me a join based on the primary key which was bad, but at least it wasn't null, but that was only when I loaded the RoomItem (see below) as part of a collection. If I used get(id, type) to get the room item, then the ReadOnlyProperties collection was undefined.

I can get around this by using criteria to return a list of ReadOnlyProperties, but it'd be nice to have it in my AssetRoomItem object.

Thanks,

Brett.

Hibernate version: NHibernate 1.2.0.Alpha1
Name and version of the database you are using:SQL Server 2000
Mapping File:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" schema="dbo">
<class name="Domain.RoomItem, Core" table="nrp_RoomItem">
<id name="ID" type="Int32" column="RoomItemID" unsaved-value="0">
<generator class="identity" />
</id>
<many-to-one name="OnLayer" column="LayerID" class="Domain.Layer, Core" />
<many-to-one name="OfCategory" column="CategoryID" class="Domain.Category, Core" />
<map name="Properties" inverse="true" cascade="all" lazy="true">
<key column="RoomItemID" />
<index column="PropertyID" type="System.Int32"/>
<one-to-many class="Domain.RoomItemProperty, Core" />
</map>
<joined-subclass name="Domain.AssetRoomItem, Core" table="nrp_AssetRoomItem">
<key column="RoomItemID"/>
<property name="AssetID" type="Int32"/>
<bag name="ReadOnlyProperties" inverse="true" lazy="true">
<key column="AssetID" foreign-key="AssetID" />
<one-to-many class="Domain.ReadOnlyAssetProperty, Core" />
</bag>
</joined-subclass>
</class>
</hibernate-mapping>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" default-lazy="false">
<class
name="Domain.ReadOnlyAssetProperty, Core"
table="dbo.nrp_AssetPropertyView" mutable="false">
<composite-id name="CompositeID" class="Domain.ReadOnlyAssetPropertyID, Core" >
<key-property name="AssetID" column="AssetID" type="Int32" />
<key-property name="ID" column="PropertyID" type="Int32"/>
</composite-id>
<property name="Value" column="Value"/>
</class>
</hibernate-mapping>


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.