Hibernate ORM
  1. Hibernate ORM
  2. HHH-8164

Deprecate @Sort in favor of @SortNatural and @SortComparator

    Details

    • Type: Task Task
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 4.3.0.Beta2
    • Component/s: annotations
    • Labels:
      None
    • Last commented by a user?:
      true

      Description

      This addresses the todo in Sort about the type checking on the comparator() attribute.

        Issue Links

          Activity

          Hide
          Steve Ebersole added a comment -

          Some other options:

          1. Re-purpose @Sort to simply define that we want the set/map to be sorted. A comparator to apply could be broken out into a separate annotation. @Comparator? @SortComparator? If that companion annotation was not present, @Sort would indicate a natural sort.
          2. Distinct annotations, as mentioned in subject. @NaturalSort and @ComparatorSort. Although Emmanuel mentioned that it might be better to use @SortNaturally and @SortByComparator because of auto-completion in Eclipse not supporting middle-matching the way IntelliJ does.

          Personally I prefer the first approach:

          public @interface Sort {
          }
          
          public @interface SortComparator {
              Class<? extends Comparator> value();
          }
          
          @Entity
          public class Order {
              ...
              @OneToMany( mappedBy="order" )
              @Sort
              @SortComparator( OrderLineItemNumberComparator.class )
              public SortedSet<LineItem> getLineItems();
          }
          
          public class OrderLineItemNumberComparator implements Comparator<LineItem> {
              ...
          }
          
          Show
          Steve Ebersole added a comment - Some other options: Re-purpose @Sort to simply define that we want the set/map to be sorted. A comparator to apply could be broken out into a separate annotation. @Comparator ? @SortComparator ? If that companion annotation was not present, @Sort would indicate a natural sort. Distinct annotations, as mentioned in subject. @NaturalSort and @ComparatorSort . Although Emmanuel mentioned that it might be better to use @SortNaturally and @SortByComparator because of auto-completion in Eclipse not supporting middle-matching the way IntelliJ does. Personally I prefer the first approach: public @ interface Sort { } public @ interface SortComparator { Class <? extends Comparator> value(); } @Entity public class Order { ... @OneToMany( mappedBy= "order" ) @Sort @SortComparator( OrderLineItemNumberComparator.class ) public SortedSet<LineItem> getLineItems(); } public class OrderLineItemNumberComparator implements Comparator<LineItem> { ... }

            People

            • Assignee:
              Steve Ebersole
              Reporter:
              Steve Ebersole
              Participants:
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - Not Specified
                Not Specified
                Logged:
                Time Spent - 2h 25m
                2h 25m

                  Development