Author: ppoddar
Date: Fri Aug 1 16:59:11 2008
New Revision: 681909
URL: http://svn.apache.org/viewvc?rev=681909&view=rev
Log:
OPENJPA-550: Correct example usage
Modified:
openjpa/trunk/openjpa-project/src/doc/manual/jpa_overview_arch.xml
Modified: openjpa/trunk/openjpa-project/src/doc/manual/jpa_overview_arch.xml
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-project/src/doc/manual/jpa_overview_arch.xml?rev=681909&r1=681908&r2=681909&view=diff
==============================================================================
--- openjpa/trunk/openjpa-project/src/doc/manual/jpa_overview_arch.xml
(original)
+++ openjpa/trunk/openjpa-project/src/doc/manual/jpa_overview_arch.xml Fri Aug
1 16:59:11 2008
@@ -195,33 +195,37 @@
Interaction of Interfaces Outside Container
</title>
<programlisting>
-// get an EntityManagerFactory using the Persistence class; typically
-// the factory is cached for easy repeated use
-EntityManagerFactory factory = Persistence.createEntityManagerFactory(null);
-
-// get an EntityManager from the factory
-EntityManager em =
factory.createEntityManager(PersistenceContextType.EXTENDED);
-
-// updates take place within transactions
-EntityTransaction tx = em.getTransaction();
-tx.begin();
+ // get an EntityManagerFactory using the Persistence class
+ // It is not recommended to obtain a factory often, as construction of a
+ // factory is a costly operation. Typically you will like to cache
+ // a factory and then refer it for repeated use
+ EntityManagerFactory factory = Persistence.createEntityManagerFactory(null);
+
+ // get an EntityManager from the factory
+ EntityManager em = factory.createEntityManager();
+
+ // Begin a transaction
+ em.getTransaction().begin();
+
+ // query for all employees who work in our research division
+ // and put in over 40 hours a week average
+ Query query = em.createQuery("SELECT e " +
+ " FROM Employee e " +
+ " WHERE e.division.name = 'Research' " +
+ " AND e.avgHours > 40");
+ List results = query.getResultList ();
-// query for all employees who work in our research division
-// and put in over 40 hours a week average
-Query query = em.createQuery("select e from Employee e where "
- + "e.division.name = 'Research' AND e.avgHours > 40");
-List results = query.getResultList ();
-
-// give all those hard-working employees a raise
-for (Object res : results) {
+ // give all those hard-working employees a raise
+ for (Object res : results) {
Employee emp = (Employee) res;
emp.setSalary(emp.getSalary() * 1.1);
-}
+ }
-// commit the updates and free resources
-tx.commit();
-em.close();
-factory.close();
+ // commit will detect all updated entities and save them in database
+ em.getTransaction().commit();
+
+ // free the resources
+ em.close();
</programlisting>
</example>
<para>