Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] N-M-Table and Additional Fields

Modeling the join table as a domain class is the best solution.

Another solution in JPA 2.0 (EclipseLink 2.0 dev stream), is to use the new
MapKey support to define the relationship.  The key could be the Job and the
value the salary.

But I would go with the class, as you may find you want other fields in the
"Employment" object in the future (such as startDate, yearsOfService, etc.).



Joe Mc. wrote:
> 
> So, one solution could be to use explicit the n-m-Table as domain class
> and use ManyToOne on both sides to this n-m-Table domain class.
> The Person contains a list of Person_has_Job objects, instead of Job
> objects. The same on the Job side.
> 
> I do not like this solution.
> Any (better) solutions?
> 
> 
> 
> Joe Mc. wrote:
>> 
>> Hi everybody,
>> 
>> I have following scenario:
>> 2 Tables with a n-m-relation. That means, I have a third table for the
>> n-m-Relation. In this third table I have additional fields.
>> artificial Example:
>> Person has a Job and the Job could be done from more tha one Person. But
>> the salary is not for every Person and Job the same.
>> Tables:
>> Person(id, name)
>> Job(id, title)
>> Person_has_Job(person_id, job_id, salary)
>> 
>> Ok. How is the JPA realisation? ;-)
>> I can work with ManyToMany and I can define with JoinTable the n-m-table.
>> But how is it possible to set the salary value in a (transient) property
>> of Job (Job#salary)
>> 
>> I think the example and the reason are clear. Howevery I do not know the
>> best solution with JPA.
>> Any Hints?
>> 
>> Thanks in advance!
>> 
>> M.Joe
>> 
>> 
>> 
>> 
>> 
>> 
> 
> 


-----
---
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
-- 
View this message in context: http://www.nabble.com/N-M-Table-and-Additional-Fields-tp22522463p22661022.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top