I'm writing a stateless EJB. I had methods like:
public String getXxx(final String userId) throws ... {
final Query query = em.createNativeQuery(...);
query.setParameter(1, userId);
return (String)query.getSingleResult();
}
Can I cache the Query object instantiating it at load time and using it in a multi-thread environment?
private static final Query query = em.createNativeQuery(...);
public String getXxx(final String userId) throws ... {
query.setParameter(1, userId);
return (String)query.getSingleResult();
}
Thanks.