8 Replies Latest reply on Feb 27, 2009 6:28 PM by Norman Richards

    EntityQuery and ordering issue

    Jarek Gilewski Newbie

      Hello,


      I have two entities, payment and its items (simple one-to-many relation):



      @Entity
      @Table(name = "payment")
      public class Payment {     /** Identifier attribute (primary-key). */
           .
           .
           .
           @Column(name = "name", unique = true)
           @NotEmpty
           @Length(max = 30)
           private String name;
      
           @OneToMany(mappedBy = "payment", fetch=FetchType.LAZY,
                     cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE})
           private List<PaymentItem> paymentItems = new ArrayList<PaymentItem>();
           .
           .
           .
      }



      and


      @Entity
      @Table(name = "payment_item")
      public PaymentItem {
           .
           .
           .
           @ManyToOne
           @JoinColumn(name="payment_id")
           @NotNull     
           private Payment payment;
      
           @Column(name = "amount")
           @NotNull
           @Digits(integerDigits=11, fractionalDigits=2)
           private BigDecimal amount;
           .
           .
           .
      }



      For listing payment items i have created the class:


      @Name("paymentItemList")
      public class PaymentItemList extends EntityQuery<PaymentItem> {
      
           @Override
           // becouse validate() is with @Create annotation i override it to initialize the object
           public void validate() {
                super.validate();
                
                setOrderColumn("payment.name");
                setOrderDirection("asc");
                setMaxResults(20);
           }
      
           @Override
           public String getEjbql() {
                return "select pi from PaymentItem pi";
           }
      
      }



      The problem is that I cannot order the items by payment.name column. I got the error:


      java.lang.IllegalArgumentException: invalid order column
           at org.jboss.seam.framework.Query.sanitizeOrderColumn(Query.java:445)
           at org.jboss.seam.framework.Query.setOrderColumn(Query.java:436)
      



      I can see at Query.java that the column name is checked with pattern "\\w*$" (ORDER_COLUMN_PATTERN) wich i guess don't allowe the dot in the order column name.


      I check that "select pi from PaymentItems pi order by payment.name" is working OK.


      Can we chcenge the ORDER_COLUMN_PATTERN to allow ordering by related columns?


      Regards


      Jarek