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: 2 questions about non-normal usage of NHibernate Collections
PostPosted: Tue Jul 01, 2008 5:35 pm 
Beginner
Beginner

Joined: Fri May 30, 2008 3:57 pm
Posts: 26
NHibernate 1.2
.Net 3.5
SQL Server 2005



I apologize for the title, I couldn't think of anything better.

If I need to tweak the schemas to accomplish my goals, that's fine.


Here are my questions.

1. How do I create many-to-many associations with just an ID?
For example:

assume the following schema
Code:
Entity1
id

Entity2
  id

Entity1_Entity2
entity1_id
entity2_id


NOTE: mapping does not need to be bi-directional, Entity1 is the parent
NOTE2: I'm currenting using an ISet/HashedSet<> in the C# entity, but I'm completely flexible on this.
NOTE3: the association table has a composite PK to enforce unique elements in the set

if I want to insert an Entity1 record but I only have the id value of the entity2's, how would I go about doing this?


2. How do I create an ordered many-to-many association?

For example:

assume the following schema
Code:
Entity3
  id

Entity4
  id

Entity3_Entity4
  entity3_id
  entity4_id
  sequence


NOTE: mapping does not need to be bi-directional, Entity3 is the parent
NOTE2: I'm mostly confused about the configuration
NOTE3: the association table has a composite PK to enforce unique elements in the set

I want to be able to order the children (Entity4).

Hopefully that's not confusing :(


I've looked through the NHibernate documentation and didn't come across anything dealing with either of these. If I just missed it, I'd love a link to the relevant section :)

Thanks for the help.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 02, 2008 1:06 pm 
Beginner
Beginner

Joined: Fri May 30, 2008 3:57 pm
Posts: 26
I solved question #2 by using an array (it was in the documentation, I just wasn't looking hard enough).

I'm still looking for #1 though. The child entity is guaranteed to exist at this stage, I just want to be able to add it to the parent without loading it from the DB (all I have is a list of integer ID's). Any hints on how to do that?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 02, 2008 1:07 pm 
Beginner
Beginner

Joined: Fri May 30, 2008 3:57 pm
Posts: 26
I solved question #2 by using an array (it was in the documentation, I just wasn't looking hard enough).

I'm still looking for #1 though. The child entity is guaranteed to exist at this stage, I just want to be able to add it to the parent without loading it from the DB (all I have is a list of integer ID's). Any hints on how to do that?


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.