Uploaded image for project: 'Hibernate ORM'
  1. Hibernate ORM
  2. HHH-8164

Deprecate @Sort in favor of @SortNatural and @SortComparator

    Details

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

      Description

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

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

              Hide
              steve 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 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 Steve Ebersole
                  Reporter:
                  steve 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