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: Advanced Nhibernate mapping: Is this even possible?
PostPosted: Wed Aug 06, 2008 5:54 pm 
Newbie

Joined: Wed Aug 06, 2008 5:13 pm
Posts: 1
Location: Rochester
I'm using NHibernate 2.0 beta, but I have a sort-of "how on earth do I.." problem trying to map from my database design ... and I'm hoping someone with more experience can tell me if what I'm trying to do is even possible, or if I need to consider redesigning the database before I can use NHibernate.

As background, I have a basic stats application with "Models" which contain "Factors" which contain and "Levels" ... in the database, the Levels table has a foreign key to the Factors table, but they have a many:many relationship to the Models table, so there is a "ModelContent" table which shows which Levels are in each Model.

The problem is that at the object level, I need Models to contain Factors, but in the persistence layer, they're mapped many-to-many to the Levels instead, and I can't see a way to map that in NHibernate.

I've explained this with diagrams on my website ( http://huddledmasses.org/a-cry-for-help ... hibernate/ ) but essentially, Factors and Levels are reused by many Models, and any given Model may contain only a subset of the possible Levels which belong to a Factor that it contains. Rather than have two tables indicating which Factors, and then which Levels are in the Model (which NHibernate seems to require) the database has just one, for the Levels. Since the Levels belong to specific Factors, that relationship is implied (and can be retrieved with a simple join query).

Is it possible to do this in NHibernate without creating additional constructs in the database?

I mean, I'm using SQL Server 9, so if I have to I could probably create an updatable view of "ModelFactors" and even "ModelFactorLevels" and tinker with the "INSTEAD OF" triggers, but I'd rather not force that much of the OO layer logic into the server ... especially since it would create a dependency on SQL Server specifically.

--
Joel "Jaykul" Bennett


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 09, 2008 5:15 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
just stumbled over "ternary associations" in the documentation and that reminded me of your problem. Maybe that's a possible solution for you:

http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/collections.html#collections-ternary
[code]

I haven't used them yet, but for me it looks like a possible solution.

_________________
--Wolfgang


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.