users@glassfish.java.net

Toplink's em.getReference - terrible :/

From: Witold Szczerba <pljosh.mail_at_gmail.com>
Date: Fri, 22 Jun 2007 13:08:53 +0200

Hi there,
in my company, we are trying to find all the bottlenecks of our
application, which is really SLOW when one have to create some
reports...

We are very, very surprised, that TopLink's entity manager, when asked
for a reference to some entity, it actually fetches it from database!

Query q = em.createQuery("SELECT l.id FROM Loan l");
  for (Object id : q.getResultList()) {
     Loan loan = em.getReference(Loan.class,(Long) id);
  }

The code above produces countless number of queries, 6 minutes of
total mayhem :/
This is exactly what happens, when em.getReference is replaced by em.find.

Is that a bug? A feature bug?