Hi all would like to ask question about JPA syntax ,which of this 2 versions of code syntaticly better and safer?
public static Prices getPriceById(int id){
EntityManager em = DBUtil.getEntityManagerFactory().createEntityManager();
return em.find(Prices.class, id);
}
or this version :
public static Prices getPriceById(int id){
EntityManager em = DBUtil.getEntityManagerFactory().createEntityManager();
try{
Prices pr = em.find(Prices.class, id);
return pr;
}
finally{em.close();}
}