Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] JPA 2 @OrderColumn question


Some of the behavior that I've seen in using @OrderColumn is that the column value is null on insert
and then updated with the value later.
 
Brian
 
----- Original message -----
From: Noah White <emailnbw@xxxxxxxxx>
To: EclipseLink User Discussions <eclipselink-users@xxxxxxxxxxx>, guy.pelletier@xxxxxxxxxx
Subject: Re: [eclipselink-users] JPA 2 @OrderColumn question
Date: Thu, 7 Jun 2012 13:01:20 -0400
 
Hi Guy,
 
That's unfortunately what I am going to have to do in this case (see my suggestion to the list about EclipseLink using a LinkedHashSet when it sees @OrderColumn applied to a Set). 
 
BTW, I am surprised that the default value of 'nullable' is true for @OrderColumn.  Why would this column ever contain a NULL?
 
-Noah

On Jun 7, 2012, at 10:47 AM, Guy Pelletier wrote:

Hi Noah,

Likely not ideal, but you could change your model to use a List with OrderColumn and when adding a favorite desert you'll have to check the List if it already exists.

Cheers,
Guy


On 07/06/2012 10:36 AM, Noah White wrote:

On Jun 7, 2012, at 7:45 AM, Guy Pelletier wrote:

Hi Noah,

Yes, the use of an OrderColumn is currently intended to be used with a List only. You can however use the JPA OrderBy annotation instead which can be used with a Set.

Cheers,
Guy

 
 
Hi Guy,
 
Thanks for your feedback. The rub with the @OrderBy approach is it relies on a column in the related entity, however, I want/need to enforce an ordering on the the relationship.  Some pseudo code to illustrate:
 
    public class Diner {
 
@ManyToMany
@JoinTable(...)
Set<Dessert>  favoriteDesserts;
 
get/set favoriteDesserts
 
    }
 
    public class Dessert {
 
@ManyToMany(mappedBy="favoriteDesserts")
Set<Diner> favoritedBy;
 
    }
 
I want to preserve the order that a Dessert is added to the favoriteDesserts. I also want to enforce that the Set of favorite desserts does not contain duplicates.  There is no particular property of Dessert to indicate an favorited order since the favorited order should be part of the join table as it relates to that and is not unique to an instance of Dessert which is why @OrderBy isn't really going to help.
 
-Noah
 

On 06/06/2012 5:52 PM, Noah White wrote:
 
I was reading over the docs [1] regarding Eclipselink's support for @OrderColumn. It looks like this only applies to List and not Set. The reason I ask is because I have a ManyToMany bi-directional relationship (using a join table) which is a Set and is implemented with a HashSet because the collection can't have duplicates.  
 
I wanted to order the entries in this set using @OrderColumn, but it appears I can only apply this to List, however using List will break my unique requirement.  Is this understanding correct?
 
If so what is the recommended strategy for this case?
 
Thanks,
 
-Noah
 

 

_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

--

<oracle_sig_logo.gif>
Guy Pelletier

ORACLE Canada, 45 O'Connor Street Suite 400 Ottawa, Ontario Canada K1P 1A4

<green-for-email-sig_0.gif> Oracle is committed to developing practices and products that help protect the environment

_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

--

<oracle_sig_logo.gif>
Guy Pelletier

ORACLE Canada, 45 O'Connor Street Suite 400 Ottawa, Ontario Canada K1P 1A4

<green-for-email-sig_0.gif> Oracle is committed to developing practices and products that help protect the environment

_______________________________________________
eclipselink-users mailing list
 

Back to the top