you can additionally annotate the relationship to specify an order for collections in 1-to-many or many-to-many relationships. Have a look at the documentation for the "@OrderBy" annotation I hope this is what you're looking for...
posted 10 years ago
Thanks for reply.
However, is @OrderBy annotation needs extra column on Unit entity?
Because there is some Unit entity that doesn't belong to any UnitCollection, maybe this wouldn't be good......
You don't have to change the Unit entity class. The @OrderBy annotation just takes an attribute/column which should be used to sort the collection. Additionally you can choose to sort the collection elements in ascending or descending order. But that's up to you to define what kind of order makes sense for these Unit objects...
posted 10 years ago
Thanks for reply again.
Because my client should be able to change order freely regardless of other columns in Unit entity, maybe I could use something @OrderBy("unitListOrder ASC").
However, is this means there should be column "unitListOrder" in Unit entity?
As far as I know the @OrderBy annotation requires that there is an existing column/attribute with the name you give it.
From the short description of your problem it seems to me that you want to allow the client to execute some kind of query. Perhaps you could simply wrap this query logic in another method which returns the Unit collection in the order(s) the client specified. Or you could do this queries in the database layer by providing some methods for the clients of your class which use the EJB query language. This would be a little bit more flexible than just the plain @OrderBy annotation.
Does that mean by specifying order by maintains its order - whenever data is retrieved in List. Or it can still change. For example I provide order by for bag and it will map to List. so whenever i access that list will it be always in same order?
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database