-
1. Re: How to sort @OneToMany mapping class?
stefanotravelli Jan 28, 2009 3:39 PM (in response to prasad_k)You are using JPA annotations here, not seam.
What you need is @OrderBy.
Let's orderingField be a property of Test, then:
@OneToMany(fetch = FetchType.EAGER, mappedBy = "test") @OrderBy("orderingField asc") List<Test> ts = new ArrayList<Test>();
-
2. Re: How to sort @OneToMany mapping class?
prasad_k Jan 28, 2009 3:56 PM (in response to prasad_k)Thank you for reply,
but it gives exception
org.hibernate.AnnotationException: property from @OrderBy clause not found:@OneToMany(fetch = FetchType.EAGER, mappedBy = "test") @OrderBy("orderingField asc") List<Test> ts = new ArrayList<Test>();
when we use this
-
3. Re: How to sort @OneToMany mapping class?
stefanotravelli Jan 28, 2009 4:27 PM (in response to prasad_k)Make sure that the property you use in the annotation value is correct.
If the collection is a collection of Test and Test has a "name" property, then you can annotate with @OrderBy("name asc").
-
4. Re: How to sort @OneToMany mapping class?
prasad_k Jan 29, 2009 3:15 PM (in response to prasad_k)Hi Stefano Travelli,
Thank you for reply,I tried it and it was working but when i change the position of element and run the code it doesn't sort the list of element by order, and the list return zero size it doesn't map.
please help me..
Thank you
-
5. Re: How to sort @OneToMany mapping class?
daxxy Jun 26, 2009 7:29 PM (in response to prasad_k)I just got this to work (yoohoo!)
There is a syntax error above. You want
@OrderBy(clause="column_name")
where column_name is the column in table associated with the joined table. In your example, in the table associated with the test entity.
Hope this is not too late!
TDR