You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.
| Online: | 29 Members of 4187 |
| Forum: Seam Users |
05. Oct 2008, 14:03 CET | Link |
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
Is there any solution for this?
Regards
Jarek
If you do the following change in the validate() method is still failing?:
public void validate() { super.validate(); setOrderColumn("pi.payment.name"); setOrderDirection("asc"); setMaxResults(20); } }HTH.
Fer ©
No it doesn't work.
As i said the exception is IllegalArgumentException from sanitizeOrderColumn function of Query.java.
There is a checking of column name against ORDER_COLUMN_PATTERN wich is ^\w*$. This pattern don't allowe column name like 'pi.payment.name'.
I think it's a bug (SEAM version jboss-seam-2.1.0.A1).
Regards
Jarek
Please report issues against CR1.
Read about how to report a bug.
Done.
https://jira.jboss.org/jira/browse/JBSEAM-3550
This has already been changed, but just for the record, I would recommend using the setOrder() method for complex.programmatic or XML-based order contstraints. OrderColumn and direction are for UI binding, where extremely strict rules must be placed on what is valid. The intention is that if you want to loosen those restrictions, you should do it in a subclass