-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: OrderBy
PostPosted: Tue Jun 09, 2009 5:37 pm 
Newbie

Joined: Sun May 24, 2009 1:01 pm
Posts: 3
I have this scenario:

Code:
class A
{
....
private List<B> bs = ArrayList<B>();
...
   @Cascade(CascadeType.ALL)
   @ManyToMany(fetch = FetchType.LAZY)
   @JoinTable(...)
   @OrderBy("formOrder")
   public List<B> getBs()
   {
      ...
   }
}

class B
{
...
private int orderOne;
private int orderTwo;
...
}


It's a unidirectional Many-To-Many relationships between A(Owner) and B.

I need that "bs" be ordered sometimes by orderOne and sometimes by orderTwo.

I can order it using
Code:
@OrderBy("orderOne")
or
Code:
@OrderBy("orderTwo")
.

Is that possible to create something like:
Code:
private List<B> bsOrderOne = ArrayList<B>();
private List<B> bsOrderTwo = ArrayList<B>();

   @Cascade(CascadeType.ALL)
   @ManyToMany(fetch = FetchType.LAZY)
   @JoinTable(...)
   @OrderBy("orderOne")
   public List<B> getBsOrderOne()
   {
      ...
   }

   @Cascade(CascadeType.ALL)
   @ManyToMany(fetch = FetchType.LAZY)
   @JoinTable(...)
   @OrderBy("orderTwo")
   public List<B> getBsOrderTwo()
   {
      ...
   }

But using the same B, not creating another relationship?

Thanks.


Top
 Profile  
 
 Post subject: Re: OrderBy
PostPosted: Wed Jun 10, 2009 12:28 am 
Newbie

Joined: Tue Jun 09, 2009 10:52 pm
Posts: 9
Do you need the data ordered two different ways after executing a single query? If not I would suggest applying the order by at fetch time rather than setting an annotation on the field.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.