-->
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: Collections with foreign key
PostPosted: Wed Mar 15, 2006 1:29 pm 
Newbie

Joined: Mon Feb 27, 2006 9:47 am
Posts: 2
Location: Stoke-on-Trent, UK
I have a collection that maps from Uservehicle to Vehicle. Each Uservehicle will have a number of vehicles in it's Vehicles collection. The definition I have used passes the Uservehicle id to the query to select all vehicles for the collection. I believe this is the default implementation.

However, due to the complexity of my data I need to pass the usercapid field as the parameter in the query to fetch the collection, is there a way to do this? Should I be using a different relationship? I have tried <id foreign-key="usercapid" /> but this does not appear to be the correct use of this attribute.

Uservehicle.hbm.xml
Code:
   <class name="Cara.BusinessObjects.Uservehicle,Cara" table="uservehicle">

      <id name="Id" column="id" type="Int32" unsaved-value="0">
         <generator class="native"/>
      </id>
      <property column="userid" type="Int32" name="Userid" not-null="true" />
      <property column="usercapid" type="Int32" name="Usercapid" not-null="true" update="false" />
      <property column="modified" type="DateTime" name="Modified" not-null="true" />
      
      <set name="Vehicles" >
         <key column="capid" />
         <one-to-many class="Cara.BusinessObjects.Vehicle,
                    Cara" />
      </set>   
      
   </class>



Debug
Code:
2006-03-15 16:41:12,406 DEBUG 2536 NHibernate.Impl.SessionImpl - resolving associations for: [Cara.BusinessObjects.Uservehicle#8160]
2006-03-15 16:41:12,421 DEBUG 2536 NHibernate.Impl.SessionImpl - creating collection wrapper:[Cara.BusinessObjects.Uservehicle.Vehicles#8160]
2006-03-15 16:41:12,421 DEBUG 2536 NHibernate.Impl.SessionImpl - done materializing entity [Cara.BusinessObjects.Uservehicle#8160]
2006-03-15 16:41:12,421 DEBUG 2536 NHibernate.Impl.SessionImpl - initializing non-lazy collections
2006-03-15 16:41:12,421 DEBUG 2536 NHibernate.Impl.SessionImpl - initializing collection [Cara.BusinessObjects.Uservehicle.Vehicles#8160]
2006-03-15 16:41:12,421 DEBUG 2536 NHibernate.Impl.SessionImpl - checking second-level cache
2006-03-15 16:41:12,421 DEBUG 2536 NHibernate.Impl.SessionImpl - collection not cached
2006-03-15 16:41:12,421 DEBUG 2536 NHibernate.Impl.BatcherImpl - Opened new IDbCommand, open IDbCommands :1
2006-03-15 16:41:12,421 DEBUG 2536 NHibernate.Impl.BatcherImpl - Building an IDbCommand object for the SqlString: SELECT vehicles0_.capid as capid__, vehicles0_.id as id__, vehicles0_.id as id0_, vehicles0_.co2Level as co2Level0_, vehicles0_.derivative as derivative0_, vehicles0_.firstRegValue as firstRe19_0_, vehicles0_.delivery as delivery0_, vehicles0_.model as model0_, vehicles0_.otrPrice as otrPrice0_, vehicles0_.manufacturer as manufact3_0_, vehicles0_.capId as capId0_, vehicles0_.vrbRate as vrbRate0_, vehicles0_.metallicNet as metalli13_0_, vehicles0_.subtotal as subtotal0_, vehicles0_.introYear as introYear0_, vehicles0_.vrbValue as vrbValue0_, vehicles0_.vehicleDiscount as vehicle14_0_, vehicles0_.special as special0_, vehicles0_.vehicleDiscountValue as vehicle15_0_, vehicles0_.capid as capid0_, vehicles0_.metallicDiscount as metalli12_0_, vehicles0_.datasetid as datasetid0_, vehicles0_.fuel as fuel0_, vehicles0_.metallic as metallic0_, vehicles0_.listPrice as listPrice0_, vehicles0_.vat as vat0_ FROM vehicle vehicles0_ WHERE vehicles0_.capid = :vehicles0_.capid
2006-03-15 16:41:12,421 DEBUG 2536 NHibernate.Type.NullableType - binding '8160' to parameter: 0
2006-03-15 16:41:12,421 INFO 2536 NHibernate.Loader.Loader - SELECT vehicles0_.capid as capid__, vehicles0_.id as id__, vehicles0_.id as id0_, vehicles0_.co2Level as co2Level0_, vehicles0_.derivative as derivative0_, vehicles0_.firstRegValue as firstRe19_0_, vehicles0_.delivery as delivery0_, vehicles0_.model as model0_, vehicles0_.otrPrice as otrPrice0_, vehicles0_.manufacturer as manufact3_0_, vehicles0_.capId as capId0_, vehicles0_.vrbRate as vrbRate0_, vehicles0_.metallicNet as metalli13_0_, vehicles0_.subtotal as subtotal0_, vehicles0_.introYear as introYear0_, vehicles0_.vrbValue as vrbValue0_, vehicles0_.vehicleDiscount as vehicle14_0_, vehicles0_.special as special0_, vehicles0_.vehicleDiscountValue as vehicle15_0_, vehicles0_.capid as capid0_, vehicles0_.metallicDiscount as metalli12_0_, vehicles0_.datasetid as datasetid0_, vehicles0_.fuel as fuel0_, vehicles0_.metallic as metallic0_, vehicles0_.listPrice as listPrice0_, vehicles0_.vat as vat0_ FROM vehicle vehicles0_ WHERE vehicles0_.capid = :p0
2006-03-15 16:41:12,421 INFO 2536 NHibernate.Impl.BatcherImpl - Preparing SELECT vehicles0_.capid as capid__, vehicles0_.id as id__, vehicles0_.id as id0_, vehicles0_.co2Level as co2Level0_, vehicles0_.derivative as derivative0_, vehicles0_.firstRegValue as firstRe19_0_, vehicles0_.delivery as delivery0_, vehicles0_.model as model0_, vehicles0_.otrPrice as otrPrice0_, vehicles0_.manufacturer as manufact3_0_, vehicles0_.capId as capId0_, vehicles0_.vrbRate as vrbRate0_, vehicles0_.metallicNet as metalli13_0_, vehicles0_.subtotal as subtotal0_, vehicles0_.introYear as introYear0_, vehicles0_.vrbValue as vrbValue0_, vehicles0_.vehicleDiscount as vehicle14_0_, vehicles0_.special as special0_, vehicles0_.vehicleDiscountValue as vehicle15_0_, vehicles0_.capid as capid0_, vehicles0_.metallicDiscount as metalli12_0_, vehicles0_.datasetid as datasetid0_, vehicles0_.fuel as fuel0_, vehicles0_.metallic as metallic0_, vehicles0_.listPrice as listPrice0_, vehicles0_.vat as vat0_ FROM vehicle vehicles0_ WHERE vehicles0_.capid = :p0
2006-03-15 16:41:12,437 DEBUG 2536 NHibernate.Impl.BatcherImpl - Opened Reader, open Readers :1
2006-03-15 16:41:12,437 DEBUG 2536 NHibernate.Loader.Loader - result set contains (possibly empty) collection: [Cara.BusinessObjects.Uservehicle.Vehicles#8160]



Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 16, 2006 1:15 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Is the "usercapid" column part of the Vehicle primary key? In general, what does the database schema look like?


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.