Solved

hibernate one to many with 3 table

Posted on 2012-03-23
2
328 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 500 total points
ID: 37757388
0

Featured Post

Industry Leaders: 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

Suggested Solutions

Title # Comments Views Activity
V.simple question about Android packages and libraries 1 38
Oracle SQL syntax check  without executing 6 108
spring jars download 1 53
American Express @Work site and Java 4 68
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

733 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