Hi!
> I have a one-to-many bidirectional relation between two entities A and
> B. There could be several thousand B entities in the collection. I
> basically just need the first and last entities of the collection B
> when B is ordered by time.
As I see it, you only have two options: either you search the DB for those
entities as you are doing now or you add that relationship to your object
model by adding references to the "first" and "last" B to every A and updating
them accordingly whenever the collection is modified (perhaps in a @PrePersist
callback?).
If that's not an option for you, you can only try to optimize the queries you
are using now, perhaps by selecting the Bs for more than one A at a time.
HTH,
Phil
puneet.bansal@wipro.com - 06 Jun 2007 16:44 GMT
You are right Phil. I did think about adding the first and last
attributes to the A entity but I am hoping that I don't have to make a
change to the design of app as the app is working perfectly and I just
have to optimize the performance. Another option that I am exploring
is writing a native Oracle query. Oracle 9 has very powerful analytic
functions and I am hoping I can utilize those to do all this one
query.
Thanks for replying.
Puneet
> Hi!
>
[quoted text clipped - 16 lines]
>
> Phil
puneet.bansal@wipro.com - 06 Jun 2007 21:51 GMT
I managed to do all this in one query by using Oracle specific query.
But now the problem is that I get multiple rows. For each entity A, I
get two rows. Do you know how to get around this? Ultimately I need
the object A having two B entities in its collection.
Thanks.
Puneet
On Jun 6, 10:44 am, puneet.ban...@wipro.com wrote:
> You are right Phil. I did think about adding the first and last
> attributes to the A entity but I am hoping that I don't have to make a
[quoted text clipped - 27 lines]
>
> > Phil
>Environment -
>
[quoted text clipped - 21 lines]
>
>Puneet
You probably should use a native SQL query.
Eric