2017-10-20 27 views

Répondre

1

Un contexte de persistance se termine lorsque EntityManager.close() est appelé. Here's an example.

Un autre exemple tiré du lien fourni dans la question:

MagazineId mi = new MagazineId(); 
mi.isbn = "1B78-YU9L"; 
mi.title = "JavaWorld"; 

// updates should always be made within transactions; note that 
// there is no code explicitly linking the magazine or company 
// with the transaction; JPA automatically tracks all changes 
EntityManager em = emf.createEntityManager(); 
em.getTransaction().begin(); 
Magazine mag = em.find(Magazine.class, mi); 
mag.setPrice(5.99); 
Company pub = mag.getPublisher(); 
pub.setRevenue(1750000D); 
em.getTransaction().commit(); 

// or we could continue using the EntityManager... 
em.close(); 
+0

Que diriez-vous JTA géré? – pirho