2 Replies Latest reply on Oct 27, 2007 6:12 AM by pmuir

    Sorting Detail data in Master/Detail

    griffitm

      All,

      I have some seam generated pages show master/detail records. If you've used seamgen generate-entities to create entities and pages then you know what I mean. If I have a relationship between 2 tables (A) Status and (B) Deliverables -- I start from the status page viewing a list. This list can be sorted by clicking on the table headers, which re-executes the SQL query passing the order by clause based on the table header.

      However, if I drill down into a single status and you see all the deliverables associated with the selected record, these records appear in a random order.

      Is there an easy way to provide the related child data (Deliverables -- joined or sub-query) in a ordered fashion? The data is loaded from the collection that is part of the master entity, not in a separate SQL query.

      Any help would be appreciated

      Best Regards,
      MG

        • 1. Re: Sorting Detail data in Master/Detail
          griffitm

          Ok, I found that I can at least control the detail records by using the JPA annotation @OrderBy on the many to one relationship as such:

          @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="section")
          @OrderBy("dueDate")
          public Set<Deliverable> getDeliverables(){
           return this.deliverables;
          }
          


          Does anyone have any idea how to sort the list dynamically from that point forward?

          MG

          • 2. Re: Sorting Detail data in Master/Detail
            pmuir

            1) A separate entity query for that (not neat at the domain model level)
            2) Do it through Comparable and List sorts (potentially much slower than using SQL to sort