• Post Reply Bookmark Topic Watch Topic
  • New Topic

EJB3 - entityManager.createQuery reuse

 
Anurag Bhatia
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a bunch of queries in my stalesssession bean that is called quite frequently. I am trying to resuse the query but I keep running into problems with transactions.

A method in my bean -

public List foo()
{
Query query = entityManger.createQuery(queryStr); -> This call takes quite a bit of time
-> If I declare the query as a memeber variable and initialize it in the @PostContruct method
-> the second time I run into a transaction issue. How can I avoid that?
-> My aim is to remove the calls to entityManager.createQuery to speed up the method and to reuse the query
query.setParameter("test","test");
return query.getResultList();
}
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35709
408
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe it would be helpful to look at other ways to speed things up. Can you use a Named query? Can you cache the results of the call itself?
 
Anurag Bhatia
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've tried using a name query but I run into the same problem of transactions. I am already caching the query results.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!