0

Assume

  1. I have a parent entity "A" and child entities "B", "C", "D" and "E"

  2. One to Many mapping is defined with fetch type as eager for all the child entities of A which is - "B", "C", "D" and "E"

  3. B, C, D, E are tied with Many to One - "P" entity

Now when i get the "A" entity...all is being loaded and the below query takes a huge time

FROM A ORDER BY pkey DESC 

After retrieving the "A" entity..I will iterate the B and get the "P" primary key from the same. similarly i need all the primary keys of "P" associated with "B", "C", "D" and "E"

  1. Is it possible to write any HQL to get only the primary keys without loading the entire entities without considering or bypassing the annotations which is already defined with fetch type as eager?

  2. Can we change the fetch type as eager to lazy, execute separate queries for each entity to get the values?

  3. Does adding a batch size to fetch type as eager would be fruitful?

Could you please suggest how we can approach on the three and what would be the best approach to resolve this issue?

Thanks.

v.ladynev
  • 19,275
  • 8
  • 46
  • 67
Kathiresa
  • 75
  • 7

1 Answers1

0

It is hard to understand your mapping and do proposals without persistent classes ("Talk is cheap. Show me the code.").

  1. It is possible. Refer this HQL as a template (It is for childs of B only)

    select p.pid from P p inner join p.b where b.a.pid = : pidOfA

  2. You should do it of course. Refer this for an one aproach how to do it.

  3. May be batch fetching will help a bit, but I don't think It is a right strategy.

Please, read Chapter 20. Improving performance from Hibernate 5 documentation if you don't do it yet.

Community
  • 1
  • 1
v.ladynev
  • 19,275
  • 8
  • 46
  • 67