hibernate - How do I sort a linked list in hql? -


same question this, i'd in hibernate (using grails if matters).

so domain class looks this

class linkedelement {   linkedelement precedingelement   string somedata } 

and i'd query elements in linked order (where first linkedelement has null precedingelement). possible in efficient way?

you can find out @ front of line (i.e. preceding element null). unfortunately, means you're in n+1 query territory whole list.

query 1 - who's in front  query 2 - who's behind 1 query 3 - who's behind 2 .... query n - who's behind n-1 query n+1 - who's behind n -> no 1 behind n, must @ end 

referring question mentioned, don't mistake efficient syntactically concise. because dbms give convenient syntax still solving same problem either a.) performing same inefficient algorithm simplified syntax or b.) indexing things ahead of time dbms has access data efficiently though didn't model way. so, if absolutely have solve problem specified data structure using hibernate, should @ using native sql query, tuning @ database level, taking advantage of features dbms may offer in area.

if think data structure you're using, it's great representing stack. can push, pop, , top couple operations each. in general, that's unidirectional linked lists for. queue, you'd want think using bidirectional linked list since can dequeue, front, , enqueue couple operations each. dynamically adding elements list, linkedlists great. getting whole list of things in order linkedlists pretty inefficient - you're looking @ n+1 or n operations depending on single or bidirectional. instead, arraylist way go. want know third element is? cool, use index. compared linked list need use first.getnext.getnext way more efficient! if need add stuff list or use queuing or stack type application it's got drawbacks - resizing arrays expensive compared adding new link in linked list.

i wish had better answer you, @ least useful.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -