Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

hibernate one to many with 3 table

Posted on 2012-03-23
2
Medium Priority
?
332 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 1000 total points
ID: 37757388
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

618 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