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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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 ornull. The latter either returns exactly one result (getSingleResult()– or throws) or returns a list (getResultList()).