?
Solved

hibernate one to many with 3 table

Posted on 2012-03-23
2
Medium Priority
?
333 Views
Last Modified: 2012-06-08
table 1:collage
table 2: students
table 3 : teachers
one collage, multiple student and multiple teacher. how to do in hibernate one to many.
0
Comment
Question by:aaronyeo22
  • 2
2 Comments
 
LVL 7

Expert Comment

by:gudii9
ID: 37757380
Here is interesting link, explanation

You use 2 different collections mapped in nHibernate to load/update the data from/to the data store and you create a 3rd collection that exposes the 2 internal collections. The third collection isn't a real collection -- it's just an implementation of the interfaces the client code will expect (IList, IEnumerable most likely). Actually, that's all a real collection is, my point is that it doesn't have its own data store.

If you look at my modificataions to the mapping example you provided, you'll notice that I renamed the one-to-many maps to give each a different name. So what you are doing is telling nHibernate to map it as if there are 2 tables (which there are) and telling the client that there is a single collection that acts as a factory to return the appropriate object type. You need to write the code in the middle that makes it appear to the client that there is a single collection.

e.g.

Code:
public class InvoiceItems : IEnumerable, IList
{
  /* in the implementation, use the 2 internal collections
     as the data source for InvoiceItems.
  */
}


I should also point out that it may be possible to do what you are trying to do in nHibernate without adopting my approach. I don't know enough about it to be able to say it isn't in there.

https://forum.hibernate.org/viewtopic.php?f=25&t=951879
0
 
LVL 7

Accepted Solution

by:
gudii9 earned 1000 total points
ID: 37757388
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month15 days, 6 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question