we have Session in Hibernate and EntityManager in JPA.
and you can see in the table above the methods mapping.
In this section we will talk about JPA APIs
add persistence.xml , this file should be inside META-INF
add orb.hibernate dependency.
as you can see, in persistence.xml, you set the provider, in our case it is hibernate, which means we will use hibernate implementation for JPA. (other possible provider is eclipse links).
we dont have to specify the Entities we have here like what we were doing with hibernate.xml, the application will go over the classes in the class path and detect all the classes that are annotated with @Entity.
we have EntityManager which is similar to Hibernate Session
we have EntityTransaction which is similar to Hibernate Transaction.
as you can see we use persist() in JPA to save to database
another thing "infinite-finance" is the persistence-unit name that is defined in the xml file
JPA Retreiving Entities
find() is similar to get() in hibernate.
getRegerence() is similar to load() in Hibernate.
JPA Modifying Entity
here we do find()
then change the object
then on commit() the record will be updated
JPA Removing Entity
we use remove() which is similar to delete() in Hibernate
we use detach() to detach, and merge() to attach again.