What are the steps to persist an entity object?

Answer

The following steps are performed to persist an entity object.

    • Create an entity manager factory object. The EntityManagerFactory interface present in java.persistence package is used to provide an entity manager.
 
  1. EntityManagerFactory emf=Persistence.createEntityManagerFactory("Student_details");  

 

    • Obtain an entity manager from the factory.
 
  1. EntityManager em=emf.createEntityManager();  

 

    • Initialize an entity manager.
 
  1. em.getTransaction().begin();  

 

    • Persist the data into the relational database.
 
  1. em.persist(s1);  

 

    • Closing the transaction
 
  1. em.getTransaction().commit();  

 

    • Release the factory resources.
 
  1. emf.close();  
  2.     em.close();  

All jpa Questions

Ask your interview questions on jpa

Write Your comment or Questions if you want the answers on jpa from jpa Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---