em.find(Enity.classs, Id)
em.createQuery("SELECT e From Entity e WHERE e.Id=:id")
Are they equivalent? If not, How are they different?
The former might be faster because JPA provider does not have to parse the JPA query. But the resulting SQL should be exactly the same.
Also I think some providers might treat them differently with regards to caching - caching by key vs. query caching.
Finally the API is much more pleasant with find() - it either returns single entry or null. The latter either returns exactly one result (getSingleResult() - or throws) or returns a list (getResultList()).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With