Java Reference
In-Depth Information
Method
Description
T merge(T t) This allows you to merge the entity passed as a parameter
with the persistence context. It returns a managed version of
the entity to be merged.
This allows you to delete the entity passed as parameter in the
database.
void re-
move(Object o)
This allows you to search for an entity using its identifier.
T
find(Class<T>
type, Object
o)
This allows you to detach an entity from the persistence con-
text so that the changes will not be saved
void de-
tach(Object o)
The following code demonstrates how to save, read, update, and delete the data us-
ing JPA in a Java SE application:
public static void main( String[] args ) {
EntityManagerFactory emf
=Persistence.createEntityManagerFactory("chapter04PU");
EntityManager em = emf.createEntityManager();
//create entity manager
Student student = createStudent();
em.getTransaction().begin();//begin
transaction
Search WWH ::




Custom Search