Hi,
I have problem with query speed in my application. Basically during one transaction in one place in my code I read a lot of entities (less then hundred in one query but thousands of them in total) with hibernate query. This query became database bottleneck, so I run profiler. I was surprised, that after some experiments, I managed to remove that bottleneck just by using EntityManager.clear() method. My question is: is there a cleaner way to speed up query. I guess it must be related with hibernate session first level cache.
Database model:
Code:
public class E implements Serializable {
@EmbeddedId
private Id id;
}
Code:
@Embeddable
public class Id implements Serializable {
Long a;
Long b;
}
Query:
Code:
SELECT e from E e where e.id.A = :A
Without using EntityManager.clear() during transaction running this query takes about 80% of computation time.
With using EntityManager.clear() it takes like 15%
Kind regards,
Karol