-->
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: NHibernate 1:n mapping to 1:1 with restrictions
PostPosted: Tue Aug 09, 2011 7:43 am 
Newbie

Joined: Tue Aug 09, 2011 7:41 am
Posts: 1
I have my application liek this:

    I have a class Product
    I have user track this product, so class Track

Note multiple user can track one product, so the relationship between Product : Track is 1 : n

However, if user is currently signed in, it can only be 1 Track associated to Product, and in my list page, I should display a list of products with its track status for current user, something like:

Product A - Tracked on 2011-01-01
Product B - Not Tracked
Product C - Tracked on 2010-12-20
...
Thus in plain sql, I may have a query like this:

Code:
select * from Product as p
left outer join Track as t
    on t.ProductId = p.Id and t.UserId = {currentUser.Id}

But using NHibernate I find it not easy to implement, currently I have a ProductWithTrack class, which inherits from Product class and adds a Track property:

Code:
class ProductWithTrack : Product {
    Track track;
}

My effort is to map this class to Product table just the same as Product class, but how can I figure the mapping of Track property, I have tried:

one-to-many, but Track is not a collection
many-to-one / one-to-one, this requires a foreign key column in Product table which certainly not exists
Please help in this mapping problem, thanks.


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.