java - Should annotation based JPA Entity Manager be closed? -
i have used annotation using entity manager instead of using entitymanagerfactory.
@persistencecontext entitymanager entitymanager;
i searched lot regd closing of entitymanager. in places entitymanager being used
entitymanager em = emf.get().createentitymanager();
and im not sure how closing varies annotation based. use use normal jdbc connection? eg:
connection conn=databaseconnection.getconnection(); preparedstatement stmt; resultset result; stmt=conn.preparestatement("select * table id = ? "); stmt.setstring(1,id); result=stmt.executequery(); conn.close();
so, need add begin tran entitymanager, commit , close each method use? or annotation take care of all?
public class someclass{ public somemethod1(){ //use entitymanager - need close each method? } public somemethod2(){ //use entitymanager } }
or getting entirely wrong? please advice.
Comments
Post a Comment