2017-10-20 8 views
1

Java Persistence Entity Operations ATMを通じて読書、そして、それはそれで次の文があります。JPA永続コンテキストはいつ終了しますか?

JPAは永続コンテキストが終了したとき、彼らはシリアル化されたりするときに自動的にエンティティを取り外すことによって、このパターンをサポートしています。

永続コンテキストが終了していますか?それは各取引の終了時ですか? EntityManager.close()が呼び出されたときに

答えて

1

永続コンテキストは終了します。 Here's an example

問題のあるリンクから取られたもう一つの例:JTAに関する管理方法

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

? – pirho

関連する問題