Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] @ManyToMany relationship for a List?

JPA 2.0 will define a special indexed List mapping.  There is an existing bug
for this,

https://bugs.eclipse.org/bugs/show_bug.cgi?id=249037

Note, however that normally a List is used because it is just a more common
and useful mapping, even though the items in it are assumed to be unique. 
So I hope this will not change defaults, unless you annotate the mapping as
being indexed.

As for supporting duplicates, that is a separate issue.  You could also have
a List for a foreign key base OneToMany, but duplicates would not make
sense,  technically it is possible on a ManyToMany or when using a join
table, but still rare for most models to want this.  I'm not certain what
the JPA spec infers on duplicate support, but I assume it is either not
supported, or not required, or more likely unspecified.

EclipseLink has some level of duplicate support for some of our
non-relational mappings, but none currently for our relational mappings, so
thank you for logging the enhancement request.  The main issue for
relational is that things become tricky, i.e. insertion may work, but if you
remove one of the duplicates, you now need to delete them all, then insert
n-1 back.  Possible, but not something we have support for yet, it would
probably require some sort of @AllowDuplicates option, that switch the
mapping to doing a deleteAll then reinsertion on any change.  The same issue
is also relevant for BasicCollection and the new JPA 2.0 ElementCollection
mappings.
 



cowwoc wrote:
> 
> FYI, I filed a bug report for the original issue:
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=256978
> 
> Gili
> 
> 
> cowwoc wrote:
>> 
>> 
>> Tim Hollosy wrote:
>>> 
>>> Anyway, on to your second question. Implementing indexed lists. What
>>> do you mean implementing indexed lists on top of JPA?
>>> 
>>> java.util.List is already indexed..so I don't really follow your
>>> question.
>>> 
>> 
>> JPA 1.0 does not retain the element index. The best you can do is
>> @OrderBy. If the order is arbitrary (chosen by the end-user) you need to
>> rely in ordering by indexes but currently JPA will not manage indexes for
>> you under the hood. For example, if you want to insert an element between
>> two other elements you will need to update the indexes of all elements
>> that allow, etc.
>> 
>> Gili
>> 
> 
> 


-----
---
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/%40ManyToMany-relationship-for-a-List--tp20749567p20774400.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top