Help

Controls

PermLinkWikiLink

Built with Seam

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.

Forum: Seam Users Forum ListTopic List
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

6 Replies:
10. Oct 2008, 11:58 CET | Link

Is there any solution for this?

Regards

Jarek

11. Oct 2008, 14:06 CET | Link

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 ©

13. Oct 2008, 08:07 CET | Link
Hi,

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
13. Oct 2008, 12:10 CET | Link

Please report issues against CR1.

 

Read about how to report a bug.

13. Oct 2008, 13:09 CET | Link

Done.

https://jira.jboss.org/jira/browse/JBSEAM-3550

13. Oct 2008, 18:27 CET | Link

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