persistence@glassfish.java.net

Re: _at_OrderBy with Set

From: Guy Pelletier <guy.pelletier_at_oracle.com>
Date: Fri, 27 Feb 2009 11:15:26 -0500

No possible because you are getting an exception? Which version are you using?

Cheers,
Guy
  ----- Original Message -----
  From: Gary Jacobson
  To: persistence_at_glassfish.dev.java.net
  Sent: Friday, February 27, 2009 10:01 AM
  Subject: Re: @OrderBy with Set


  This is not possible... the only options for OneToMany fields are List, Set, Map and Collection

  I'm currently using the following workaround in my getter method:

      public Set<SalePurchaser> getSalePurchaserSet()
      {
          if (!(salePurchaserSet instanceof SortedSet))
              salePurchaserSet = new TreeSet<SalePurchaser>( salePurchaserSet );
          return salePurchaserSet;
      }



    ---------- Forwarded message ----------
    From: "Guy Pelletier" <guy.pelletier_at_oracle.com>
    To: <persistence_at_glassfish.dev.java.net>
    Date: Fri, 27 Feb 2009 08:32:59 -0500
    Subject: Re: @OrderBy with Set

    Might not be the ideal solution, but try:

        @OneToMany( cascade = CascadeType.ALL, mappedBy = "sale", fetch="EAGER")
        @OrderBy( value = "sequence" )
        private TreeSet<SalePurchaser> salePurchaserSet = new TreeSet<SalePurchaser>();

    Cheers,
    Guy
      ----- Original Message -----
      From: Gary Jacobson
      To: persistence_at_glassfish.dev.java.net
      Sent: Friday, February 27, 2009 6:04 AM
      Subject: @OrderBy with Set


      I have an entity which contains the following field:

          @OneToMany( cascade = CascadeType.ALL, mappedBy = "sale" )
          @OrderBy( value = "sequence" )
          private Set<SalePurchaser> salePurchaserSet = new TreeSet<SalePurchaser>();

      Unfortunately the internal Set implementation (oracle.toplink.essentials.indirection.IndirectSet) is not a SortedSet, so the @OrderBy has no effect.

      You cannot specify SortedSet or TreeSet for the field type.

      Is there any workaround for this? I'd prefer to avoid using a List if possible.

      Thanks
      Gary