Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JPA - getSingleResult() . It's very slow...

843830Apr 10 2008 — edited Apr 11 2008
Hi,

I have a problem with getSingleResult(). It seems very slow , around *400 milliseconds.*
I'm using Oracle Toplink essentials JPA implementation.

This is a piece of my code: (Do you see anything wrong in it?):

public <T> T findUniqueByX(Class<T> source_class, String field, Object value)
*{*
Object o = null;
T ot = null;

StringBuffer sbQuery = new StringBuffer();
sbQuery.append("SELECT x FROM ");
sbQuery.append(source_class.getSimpleName());
sbQuery.append(" x WHERE ");
sbQuery.append("x.");
sbQuery.append(field);
sbQuery.append("=?1");

Query q = em.createQuery(sbQuery.toString());
q.setParameter(1, value);
try
*{*
o = q.getSingleResult();
ot = source_class.cast(o);
*}*
catch (javax.persistence.NoResultException e)
*{*
ot = null;
*}*

return ot;
*}*

Thanks in advance
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 9 2008
Added on Apr 10 2008
1 comment
802 views