Moved SQL diagnostics into its own managed bean and EJB
diff --git a/jpa/employee/employee.model/src/main/java/eclipselink/example/jpa/employee/model/Employee.java b/jpa/employee/employee.model/src/main/java/eclipselink/example/jpa/employee/model/Employee.java
index 3ae747d..a10b241 100644
--- a/jpa/employee/employee.model/src/main/java/eclipselink/example/jpa/employee/model/Employee.java
+++ b/jpa/employee/employee.model/src/main/java/eclipselink/example/jpa/employee/model/Employee.java
@@ -13,25 +13,22 @@
  ******************************************************************************/
 package eclipselink.example.jpa.employee.model;
 
-import static javax.persistence.CascadeType.ALL;
-import static javax.persistence.FetchType.LAZY;
-
 import java.util.ArrayList;
 import java.util.List;
 
 import javax.persistence.AttributeOverride;
 import javax.persistence.AttributeOverrides;
 import javax.persistence.Basic;
+import javax.persistence.CascadeType;
 import javax.persistence.CollectionTable;
 import javax.persistence.Column;
 import javax.persistence.ElementCollection;
 import javax.persistence.Embedded;
 import javax.persistence.Entity;
+import javax.persistence.FetchType;
 import javax.persistence.GeneratedValue;
 import javax.persistence.Id;
 import javax.persistence.JoinColumn;
-import javax.persistence.JoinTable;
-import javax.persistence.ManyToMany;
 import javax.persistence.ManyToOne;
 import javax.persistence.NamedQueries;
 import javax.persistence.NamedQuery;
@@ -63,7 +60,7 @@
 	@NamedQuery(name = "Employee.count", query = "SELECT COUNT(e) FROM Employee e"),
 	@NamedQuery(name = "Employee.countByName", query = "SELECT COUNT(e) FROM Employee e WHERE e.firstName LIKE :firstName AND e.lastName LIKE :lastName"),
 	/**
-	 * Query used in {@link EmployeeIdInPaging}
+	 * Query used in {@link IdInPaging}
 	 */
 	@NamedQuery(name = "Employee.idsIn", query = "SELECT e FROM Employee e WHERE e.id IN :IDS ORDER BY e.id", hints = { @QueryHint(name = QueryHints.QUERY_RESULTS_CACHE, value = HintValues.TRUE) })})
 public class Employee {
@@ -95,18 +92,18 @@
     @Version
     private Long version;
     
-    @ManyToOne(fetch = LAZY)
+    @ManyToOne(fetch = FetchType.LAZY)
     @JoinColumn(name = "MANAGER_ID")
     private Employee manager;
 
     @OneToMany(mappedBy = "manager")
     private List<Employee> managedEmployees = new ArrayList<Employee>();
 
-    @OneToMany(mappedBy = "owner", cascade = ALL, orphanRemoval=true)
+    @OneToMany(mappedBy = "owner", cascade = CascadeType.ALL, orphanRemoval=true)
     @PrivateOwned
     private List<PhoneNumber> phoneNumbers = new ArrayList<PhoneNumber>();
 
-    @OneToOne(cascade = ALL, fetch = LAZY, orphanRemoval=true)
+    @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval=true)
     @JoinColumn(name = "ADDR_ID")
     private Address address;
 
diff --git a/jpa/employee/employee.model/src/main/java/eclipselink/example/jpa/employee/services/AdminBean.java b/jpa/employee/employee.model/src/main/java/eclipselink/example/jpa/employee/services/AdminBean.java
index 1ea6da5..1b014e7 100644
--- a/jpa/employee/employee.model/src/main/java/eclipselink/example/jpa/employee/services/AdminBean.java
+++ b/jpa/employee/employee.model/src/main/java/eclipselink/example/jpa/employee/services/AdminBean.java
@@ -17,8 +17,7 @@
 
 import javax.ejb.Stateless;
 import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.PersistenceUnit;
+import javax.persistence.PersistenceContext;
 import javax.persistence.metamodel.EntityType;
 
 import org.eclipse.persistence.descriptors.ClassDescriptor;
@@ -38,46 +37,35 @@
 @Stateless
 public class AdminBean {
 
-    private EntityManagerFactory emf;
+    private EntityManager entityManager;
 
-    public EntityManagerFactory getEmf() {
-        return emf;
+    public EntityManager getEntityManager() {
+        return entityManager;
     }
 
-    @PersistenceUnit(unitName = "employee")
-    public void setEmf(EntityManagerFactory emf) {
-        this.emf = emf;
+    @PersistenceContext(unitName = "employee")
+    public void setEntityManager(EntityManager entityManager) {
+        this.entityManager = entityManager;
     }
 
-    public String resetDatabase() {
-        EntityManager em = getEmf().createEntityManager();
+    public void resetDatabase() {
+        Server session = getEntityManager().unwrap(Server.class);
 
-        try {
-            SchemaManager sm = new SchemaManager(em.unwrap(Server.class));
-            sm.replaceDefaultTables();
-            sm.replaceSequences();
+        SchemaManager sm = new SchemaManager(session);
+        sm.replaceDefaultTables();
+        sm.replaceSequences();
 
-            em.unwrap(Server.class).getIdentityMapAccessor().initializeAllIdentityMaps();
-        } finally {
-            em.close();
-        }
-        return null;
+        session.getIdentityMapAccessor().initializeAllIdentityMaps();
     }
 
-    public String populateDatabase(int quantity) {
-        EntityManager em = getEmf().createEntityManager();
-
-        try {
-            new SamplePopulation().createNewEmployees(em, quantity);
-        } finally {
-            em.close();
-        }
-        return null;
+    public void populateDatabase(int quantity) {
+        new SamplePopulation().createNewEmployees(getEntityManager(), quantity);
+        getEntityManager().flush();
     }
 
     public int getCacheSize(String typeName) {
-        EntityManager em = getEmf().createEntityManager();
-        Server session = em.unwrap(Server.class);
+        Server session = getEntityManager().unwrap(Server.class);
+
         ClassDescriptor descriptor = session.getDescriptorForAlias(typeName);
         if (descriptor != null) {
             return ((IdentityMapAccessor) session.getIdentityMapAccessor()).getIdentityMap(descriptor.getJavaClass()).getSize();
@@ -87,13 +75,7 @@
     }
 
     public int getDatabaseCount(String type) {
-        EntityManager em = getEmf().createEntityManager();
-
-        try {
-            return em.createQuery("SELECT COUNT(o) FROM " + type + " o", Number.class).getSingleResult().intValue();
-        } finally {
-            em.close();
-        }
+            return getEntityManager().createQuery("SELECT COUNT(o) FROM " + type + " o", Number.class).getSingleResult().intValue();
     }
 
     /**
@@ -102,7 +84,7 @@
      */
     public List<String> getTypes() {
         List<String> typeNames = new ArrayList<String>();
-        for (EntityType<?> type : getEmf().getMetamodel().getEntities()) {
+        for (EntityType<?> type : getEntityManager().getMetamodel().getEntities()) {
             if (type.getSupertype() == null) {
                 typeNames.add(type.getName());
             }
diff --git a/jpa/employee/employee.model/src/main/java/eclipselink/example/jpa/employee/services/Diagnostics.java b/jpa/employee/employee.model/src/main/java/eclipselink/example/jpa/employee/services/Diagnostics.java
deleted file mode 100644
index dfcffd4..0000000
--- a/jpa/employee/employee.model/src/main/java/eclipselink/example/jpa/employee/services/Diagnostics.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010-2013 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the 
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 
- * which accompanies this distribution. 
- * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at 
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- *  dclarke - initial
- ******************************************************************************/
-package eclipselink.example.jpa.employee.services;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.ejb.Local;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-
-import org.eclipse.persistence.logging.SessionLog;
-import org.eclipse.persistence.logging.SessionLogEntry;
-import org.eclipse.persistence.sessions.server.Server;
-
-/**
- * SessionLog proxy {@link InvocationHandler} used to intercept SQL logging
- * messages so this sample application can display the SQL executed by the most
- * recent operations.
- * 
- * @author dclarke
- * @since EclipseLink 2.4.2
- */
-@Local
-public class Diagnostics implements InvocationHandler {
-
-    /**
-     * property name to store {@link Diagnostics} instance for a given
-     * {@link EntityManagerFactory} within its {@link Server} session's
-     * properties.
-     */
-    private static final String DIAGNOSTICS = Diagnostics.class.getName();
-
-    private ThreadLocal<SQLTrace> traces = new ThreadLocal<SQLTrace>();
-    private SessionLog log;
-
-    /**
-     * Lookup the Diagnostics instance and registered as the SessionLog (proxy).
-     * If one does not exist then create one.
-     */
-    public static Diagnostics getInstance(EntityManagerFactory emf) {
-        EntityManager em = emf.createEntityManager();
-        try {
-            return getInstance(em);
-        } finally {
-            em.close();
-        }
-    }
-
-    public static Diagnostics getInstance(EntityManager em) {
-        Server session = em.unwrap(Server.class);
-
-        Diagnostics diagnostics = (Diagnostics) session.getProperty(DIAGNOSTICS);
-
-        if (diagnostics == null) {
-            synchronized (em.unwrap(Server.class)) {
-                diagnostics = (Diagnostics) session.getProperty(DIAGNOSTICS);
-                if (diagnostics == null) {
-                    diagnostics = new Diagnostics(session);
-                    session.setProperty(DIAGNOSTICS, diagnostics);
-                }
-            }
-        }
-
-        return diagnostics;
-
-    }
-
-    protected Diagnostics(Server session) {
-        this.log = session.getSessionLog();
-        SessionLog logProxy = (SessionLog) Proxy.newProxyInstance(session.getPlatform().getConversionManager().getLoader(), new Class[] { SessionLog.class }, this);
-        session.setSessionLog(logProxy);
-    }
-
-    public SessionLog getLog() {
-        return this.log;
-    }
-
-    public SQLTrace getTrace() {
-        return this.traces.get();
-    }
-
-    public SQLTrace start() {
-        SQLTrace trace = getTrace();
-
-        if (trace == null) {
-            trace = new SQLTrace();
-            this.traces.set(trace);
-        }
-        return trace;
-    }
-
-    public SQLTrace stop() {
-        SQLTrace trace = getTrace();
-        this.traces.set(null);
-        return trace;
-    }
-
-    @Override
-    public Object invoke(Object source, Method method, Object[] args) throws Throwable {
-        SQLTrace trace = getTrace();
-
-        if (trace != null && "log".equals(method.getName()) && args.length == 1) {
-            SessionLogEntry entry = (SessionLogEntry) args[0];
-            if (SessionLog.SQL.equals(entry.getNameSpace())) {
-                trace.add(entry.getMessage());
-            }
-        }
-
-        return method.invoke(getLog(), args);
-
-    }
-
-    public static class SQLTrace {
-
-        private List<String> entries = new ArrayList<String>();
-
-        protected void add(String entry) {
-            this.entries.add(entry);
-        }
-
-        public List<String> getEntries() {
-            return entries;
-        }
-
-    }
-}
diff --git a/jpa/employee/employee.model/src/main/java/eclipselink/example/jpa/employee/services/EmployeeCriteria.java b/jpa/employee/employee.model/src/main/java/eclipselink/example/jpa/employee/services/EmployeeCriteria.java
index dd296b9..37790bf 100644
--- a/jpa/employee/employee.model/src/main/java/eclipselink/example/jpa/employee/services/EmployeeCriteria.java
+++ b/jpa/employee/employee.model/src/main/java/eclipselink/example/jpa/employee/services/EmployeeCriteria.java
@@ -27,7 +27,8 @@
 import eclipselink.example.jpa.employee.services.paging.IdInPaging;
 
 /**
- * TODO
+ * Search criteria definition. View layer populates this criteria and passes it
+ * to the services layer for execution.
  * 
  * @author dclarke
  * @since EclipseLInk 2.4.2
diff --git a/jpa/employee/employee.model/src/main/java/eclipselink/example/jpa/employee/services/EmployeeRepository.java b/jpa/employee/employee.model/src/main/java/eclipselink/example/jpa/employee/services/EmployeeRepository.java
index 75d2146..1407d14 100644
--- a/jpa/employee/employee.model/src/main/java/eclipselink/example/jpa/employee/services/EmployeeRepository.java
+++ b/jpa/employee/employee.model/src/main/java/eclipselink/example/jpa/employee/services/EmployeeRepository.java
@@ -37,8 +37,6 @@
 
     private EntityManager entityManager;
 
-    private Diagnostics diagnostics;
-
     public EntityManager getEntityManager() {
         return entityManager;
     }
@@ -46,15 +44,15 @@
     @PersistenceContext(unitName = "employee")
     public void setEntityManager(EntityManager entityManager) {
         this.entityManager = entityManager;
-        this.diagnostics = Diagnostics.getInstance(entityManager);
     }
 
-    public Diagnostics getDiagnostics() {
-        return diagnostics;
-    }
-
-    public Employee find(int id) {
-        return getEntityManager().find(Employee.class, id);
+    public Employee find(int id, boolean complete) {
+        Employee emp = getEntityManager().find(Employee.class, id);
+        if (complete && emp != null) {
+            emp.getAddress();
+            emp.getPhoneNumbers().size();
+        }
+        return emp;
     }
 
     /**
@@ -81,15 +79,24 @@
         return emp;
     }
 
-    public void delete(Employee employee) {
-        Employee emp = getEntityManager().merge(employee);
-        getEntityManager().remove(emp);
-        getEntityManager().flush();
+    public Employee delete(Employee employee) {
+        try {
+            Employee emp = getEntityManager().find(Employee.class, employee.getId());
+            getEntityManager().remove(emp);
+            getEntityManager().flush();
+            return emp;
+        } catch (OptimisticLockException ole) {
+            return null;
+        }
     }
 
     public Employee refresh(Employee employee) {
         Employee emp = getEntityManager().find(Employee.class, employee.getId());
         getEntityManager().refresh(emp);
+
+        emp.getAddress();
+        emp.getPhoneNumbers().size();
+
         return emp;
     }
 
@@ -133,4 +140,5 @@
         CriteriaQuery<Employee> cq = criteria.createQuery(getEntityManager());
         return getEntityManager().createQuery(cq).getResultList();
     }
+
 }
diff --git a/jpa/employee/employee.model/src/main/java/eclipselink/example/jpa/employee/services/diagnostics/Diagnostics.java b/jpa/employee/employee.model/src/main/java/eclipselink/example/jpa/employee/services/diagnostics/Diagnostics.java
new file mode 100644
index 0000000..7c49489
--- /dev/null
+++ b/jpa/employee/employee.model/src/main/java/eclipselink/example/jpa/employee/services/diagnostics/Diagnostics.java
@@ -0,0 +1,129 @@
+/*******************************************************************************
+ * Copyright (c) 2010-2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the 
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 
+ * which accompanies this distribution. 
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at 
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *  dclarke - initial
+ ******************************************************************************/
+package eclipselink.example.jpa.employee.services.diagnostics;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ejb.Singleton;
+import javax.ejb.Startup;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.PersistenceUnit;
+
+import org.eclipse.persistence.logging.SessionLog;
+import org.eclipse.persistence.logging.SessionLogEntry;
+import org.eclipse.persistence.sessions.server.Server;
+
+/**
+ * SessionLog proxy {@link InvocationHandler} used to intercept SQL logging
+ * messages so this sample application can display the SQL executed by the most
+ * recent operations.
+ * 
+ * @author dclarke
+ * @since EclipseLink 2.4.2
+ */
+@Singleton
+@Startup
+public class Diagnostics {
+
+    private boolean enabled = true;
+
+    private EntityManagerFactory emf;
+
+    private ThreadLocal<SQLTrace> traces = new ThreadLocal<SQLTrace>();
+
+    public EntityManagerFactory getEmf() {
+        return emf;
+    }
+
+    @PersistenceUnit(unitName = "employee")
+    public void setEmf(EntityManagerFactory emf) {
+        this.emf = emf;
+
+        EntityManager em = emf.createEntityManager();
+        Server session = em.unwrap(Server.class);
+        SessionLog original = session.getSessionLog();
+        SessionLog logProxy = (SessionLog) Proxy.newProxyInstance(session.getPlatform().getConversionManager().getLoader(), new Class[] { SessionLog.class }, new SessionLogHandler(original));
+        session.setSessionLog(logProxy);
+
+        em.close();
+    }
+
+    public boolean isEnabled() {
+        return enabled;
+    }
+
+    public void setEnabled(boolean enabled) {
+        this.enabled = enabled;
+    }
+
+    public SQLTrace getTrace() {
+        return getTrace(false);
+    }
+
+    public SQLTrace getTrace(boolean close) {
+        SQLTrace trace = this.traces.get();
+
+        if (close) {
+            clear();
+        } else if (trace == null) {
+            trace = new SQLTrace();
+            this.traces.set(trace);
+        }
+        return trace;
+    }
+    
+    public void clear() {
+        this.traces.set(null);
+    }
+
+    private class SessionLogHandler implements InvocationHandler {
+
+        private SessionLog sessionLog;
+
+        private SessionLogHandler(SessionLog log) {
+            this.sessionLog = log;
+        }
+
+        @Override
+        public Object invoke(Object source, Method method, Object[] args) throws Throwable {
+            if (isEnabled() && "log".equals(method.getName()) && args.length == 1) {
+                SessionLogEntry entry = (SessionLogEntry) args[0];
+                if (SessionLog.SQL.equals(entry.getNameSpace())) {
+                    getTrace(false).add(entry.getMessage());
+                }
+            }
+
+            return method.invoke(this.sessionLog, args);
+        }
+
+    }
+
+    public static class SQLTrace {
+
+        private List<String> entries = new ArrayList<String>();
+
+        protected void add(String entry) {
+            this.entries.add(entry);
+        }
+
+        public List<String> getEntries() {
+            return entries;
+        }
+
+    }
+}
diff --git a/jpa/employee/employee.model/src/main/java/eclipselink/example/jpa/employee/services/diagnostics/DiagnosticsInterceptor.java b/jpa/employee/employee.model/src/main/java/eclipselink/example/jpa/employee/services/diagnostics/DiagnosticsInterceptor.java
new file mode 100644
index 0000000..8d2d789
--- /dev/null
+++ b/jpa/employee/employee.model/src/main/java/eclipselink/example/jpa/employee/services/diagnostics/DiagnosticsInterceptor.java
@@ -0,0 +1,53 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the 
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 
+ * which accompanies this distribution. 
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at 
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *  dclarke - initial
+ ******************************************************************************/
+package eclipselink.example.jpa.employee.services.diagnostics;
+
+import javax.ejb.EJB;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptor;
+import javax.interceptor.InvocationContext;
+
+/**
+ * TODO
+ * 
+ * @author dclarke
+ * @since EclipseLink 2.4.2
+ */
+@Interceptor
+public class DiagnosticsInterceptor {
+
+    private Diagnostics diagnostics;
+
+    @EJB
+    public void setDiagnostics(Diagnostics diagnostics) {
+        this.diagnostics = diagnostics;
+    }
+
+    public Diagnostics getDiagnostics() {
+        return diagnostics;
+    }
+
+    @AroundInvoke
+    public Object intercept(InvocationContext ctx) throws Exception {
+        System.out.println("*** DiagnosticsInterceptor intercepting " + ctx.getMethod().getName());
+
+        try {
+            return ctx.proceed();
+        } finally {
+            if (!ctx.getMethod().getName().equals("getDiagnostics")) {
+                System.out.println("*** DiagnosticsInterceptor exiting");
+            }
+        }
+    }
+
+}
diff --git a/jpa/employee/employee.model/src/test/java/eclipselink/example/jpa/employee/test/services/AdminBeanTest.java b/jpa/employee/employee.model/src/test/java/eclipselink/example/jpa/employee/test/services/AdminBeanTest.java
index 78501f2..0355969 100644
--- a/jpa/employee/employee.model/src/test/java/eclipselink/example/jpa/employee/test/services/AdminBeanTest.java
+++ b/jpa/employee/employee.model/src/test/java/eclipselink/example/jpa/employee/test/services/AdminBeanTest.java
@@ -17,6 +17,7 @@
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 
+import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Assert;
 import org.junit.Before;
@@ -24,7 +25,6 @@
 import org.junit.Test;
 
 import eclipselink.example.jpa.employee.model.SamplePopulation;
-import eclipselink.example.jpa.employee.services.Diagnostics;
 import eclipselink.example.jpa.employee.services.AdminBean;
 import eclipselink.example.jpa.employee.test.PersistenceTesting;
 
@@ -49,14 +49,11 @@
         verifyReset();
 
         getAdmin().populateDatabase(20);
-
-        Assert.assertEquals(20, admin.getCacheSize("Employee"));
+        
         Assert.assertEquals(20, admin.getDatabaseCount("Employee"));
 
-        Assert.assertEquals(20, admin.getCacheSize("Address"));
         Assert.assertEquals(20, admin.getDatabaseCount("Address"));
 
-        Assert.assertEquals(40, admin.getCacheSize("PhoneNumber"));
         Assert.assertEquals(40, admin.getDatabaseCount("PhoneNumber"));
     }
 
@@ -78,13 +75,6 @@
         return emf;
     }
 
-    @Before
-    public void resetDatabase() {
-        this.admin = new AdminBean();
-        this.admin.setEmf(getEmf());
-        this.admin.resetDatabase();
-    }
-
     @BeforeClass
     public static void createEMF() {
         emf = PersistenceTesting.createEMF(true);
@@ -95,7 +85,6 @@
         em.getTransaction().commit();
         em.close();
 
-        Diagnostics.getInstance(emf);
         emf.getCache().evictAll();
     }
 
@@ -107,4 +96,24 @@
         emf = null;
     }
 
+    @Before
+    public void setup() {
+        EntityManager em = getEmf().createEntityManager();
+        this.admin = new AdminBean();
+        this.admin.setEntityManager(em);
+
+        em.getTransaction().begin();
+        this.admin.resetDatabase();
+        em.getTransaction().commit();
+        em.clear();
+
+        em.getTransaction().begin();
+    }
+
+    @After
+    public void close() {
+        this.admin.getEntityManager().getTransaction().commit();
+        this.admin.getEntityManager().close();
+    }
+
 }
diff --git a/jpa/employee/employee.model/src/test/java/eclipselink/example/jpa/employee/test/services/DiagnosticsTest.java b/jpa/employee/employee.model/src/test/java/eclipselink/example/jpa/employee/test/services/DiagnosticsTest.java
index 351897f..53b0098 100644
--- a/jpa/employee/employee.model/src/test/java/eclipselink/example/jpa/employee/test/services/DiagnosticsTest.java
+++ b/jpa/employee/employee.model/src/test/java/eclipselink/example/jpa/employee/test/services/DiagnosticsTest.java
@@ -21,13 +21,14 @@
 import org.eclipse.persistence.sessions.server.Server;
 import org.junit.AfterClass;
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
 import eclipselink.example.jpa.employee.model.Employee;
 import eclipselink.example.jpa.employee.model.SamplePopulation;
-import eclipselink.example.jpa.employee.services.Diagnostics;
-import eclipselink.example.jpa.employee.services.Diagnostics.SQLTrace;
+import eclipselink.example.jpa.employee.services.diagnostics.Diagnostics;
+import eclipselink.example.jpa.employee.services.diagnostics.Diagnostics.SQLTrace;
 import eclipselink.example.jpa.employee.test.PersistenceTesting;
 
 public class DiagnosticsTest {
@@ -41,21 +42,20 @@
 
         Assert.assertNotNull(log);
         Assert.assertTrue(Proxy.isProxyClass(log.getClass()));
-        Assert.assertTrue(Proxy.getInvocationHandler(log) instanceof Diagnostics);
+        Assert.assertEquals(Diagnostics.class.getName() + "$SessionLogHandler", Proxy.getInvocationHandler(log).getClass().getName());
 
         em.close();
     }
 
     @Test
     public void singleFind() {
-        Diagnostics diagnostics = Diagnostics.getInstance(getEmf());
         EntityManager em = getEmf().createEntityManager();
 
-        SQLTrace start = diagnostics.start();
+        SQLTrace start = diagnostics.getTrace();
         Assert.assertEquals(0, start.getEntries().size());
 
         em.find(Employee.class, 1);
-        SQLTrace trace = diagnostics.stop();
+        SQLTrace trace = diagnostics.getTrace(true);
 
         Assert.assertSame(trace, start);
         Assert.assertNotNull(trace);
@@ -66,6 +66,8 @@
 
     private static EntityManagerFactory emf;
 
+    private static Diagnostics diagnostics;
+
     public static EntityManagerFactory getEmf() {
         return emf;
     }
@@ -73,6 +75,8 @@
     @BeforeClass
     public static void createEMF() {
         emf = PersistenceTesting.createEMF(true);
+        diagnostics = new Diagnostics();
+        diagnostics.setEmf(emf);
 
         EntityManager em = emf.createEntityManager();
         em.getTransaction().begin();
@@ -80,7 +84,6 @@
         em.getTransaction().commit();
         em.close();
 
-        Diagnostics.getInstance(emf);
         emf.getCache().evictAll();
     }
 
@@ -92,4 +95,9 @@
         emf = null;
     }
 
+    @Before
+    public void clear() {
+        diagnostics.clear();
+    }
+
 }
diff --git a/jpa/employee/employee.model/src/test/java/eclipselink/example/jpa/employee/test/services/EditEmployeeTest.java b/jpa/employee/employee.model/src/test/java/eclipselink/example/jpa/employee/test/services/EditEmployeeTest.java
index 4012dd0..36bee03 100644
--- a/jpa/employee/employee.model/src/test/java/eclipselink/example/jpa/employee/test/services/EditEmployeeTest.java
+++ b/jpa/employee/employee.model/src/test/java/eclipselink/example/jpa/employee/test/services/EditEmployeeTest.java
@@ -38,7 +38,7 @@
 
     @Test
     public void saveWithoutChanges() {
-        Employee emp = this.repository.find(sampleId);
+        Employee emp = this.repository.find(sampleId, true);
 
         Assert.assertNotNull(emp);
 
@@ -47,7 +47,7 @@
 
     @Test
     public void incrementSalary() {
-        Employee emp = this.repository.find(sampleId);
+        Employee emp = this.repository.find(sampleId, true);
 
         emp.setSalary(emp.getSalary() + 1);
 
@@ -56,24 +56,20 @@
 
     @Test
     public void optimisticLockFailure() {
-        Employee emp = this.repository.find(sampleId);
+        Employee emp = this.repository.find(sampleId, true);
 
-        try {
-            repository.updateVersion(emp);
-            emp.setSalary(emp.getSalary() + 1);
-            repository.save(emp);
+        repository.updateVersion(emp);
+        emp.setSalary(emp.getSalary() + 1);
 
-        } catch (OptimisticLockException e) {
-            getRepository().getEntityManager().getTransaction().rollback();
-            return;
-        }
+        Employee result = repository.save(emp);
 
-        Assert.fail("OptimisticLockException not thrown");
+        Assert.assertNull(result);
+        repository.getEntityManager().getTransaction().rollback();
     }
 
     @Test
     public void refreshUpdateAddress() {
-        Employee emp = this.repository.find(sampleId);
+        Employee emp = this.repository.find(sampleId, true);
 
         emp = repository.refresh(emp);
         emp.getAddress().setCity("Ottawa");
diff --git a/jpa/employee/employee.model/src/test/java/eclipselink/example/jpa/employee/test/services/PageEmployeesTest.java b/jpa/employee/employee.model/src/test/java/eclipselink/example/jpa/employee/test/services/PageEmployeesTest.java
index a1becc9..19d9ac3 100644
--- a/jpa/employee/employee.model/src/test/java/eclipselink/example/jpa/employee/test/services/PageEmployeesTest.java
+++ b/jpa/employee/employee.model/src/test/java/eclipselink/example/jpa/employee/test/services/PageEmployeesTest.java
@@ -26,11 +26,11 @@
 
 import eclipselink.example.jpa.employee.model.Employee;
 import eclipselink.example.jpa.employee.model.SamplePopulation;
-import eclipselink.example.jpa.employee.services.Diagnostics;
-import eclipselink.example.jpa.employee.services.EmployeeRepository;
-import eclipselink.example.jpa.employee.services.Diagnostics.SQLTrace;
-import eclipselink.example.jpa.employee.services.paging.EntityPaging;
 import eclipselink.example.jpa.employee.services.EmployeeCriteria;
+import eclipselink.example.jpa.employee.services.EmployeeRepository;
+import eclipselink.example.jpa.employee.services.diagnostics.Diagnostics;
+import eclipselink.example.jpa.employee.services.diagnostics.Diagnostics.SQLTrace;
+import eclipselink.example.jpa.employee.services.paging.EntityPaging;
 import eclipselink.example.jpa.employee.test.PersistenceTesting;
 
 /**
@@ -44,7 +44,7 @@
     @Test
     public void page5ByIndex() {
 
-        SQLTrace start = getDiagnostics().start();
+        SQLTrace start = diagnostics.getTrace();
         Assert.assertTrue(start.getEntries().isEmpty());
 
         EmployeeCriteria criteria = new EmployeeCriteria();
@@ -52,12 +52,12 @@
         criteria.setLastName(null);
         criteria.setPageSize(5);
         criteria.setPagingType(EntityPaging.Type.PAGE.name());
-        
+
         EntityPaging<Employee> paging = getRepository().getPaging(criteria);
-        
+
         Assert.assertEquals(25, paging.size());
 
-        SQLTrace end = getDiagnostics().stop();
+        SQLTrace end = diagnostics.getTrace(true);
 
         Assert.assertNotNull(end);
         Assert.assertSame(start, end);
@@ -80,7 +80,7 @@
     @Test
     public void page5ByNext() {
 
-        SQLTrace start = getDiagnostics().start();
+        SQLTrace start = diagnostics.getTrace();
         Assert.assertTrue(start.getEntries().isEmpty());
 
         EmployeeCriteria criteria = new EmployeeCriteria();
@@ -88,12 +88,12 @@
         criteria.setLastName(null);
         criteria.setPageSize(5);
         criteria.setPagingType(EntityPaging.Type.PAGE.name());
-        
+
         EntityPaging<Employee> paging = getRepository().getPaging(criteria);
 
         Assert.assertEquals(25, paging.size());
 
-        SQLTrace end = getDiagnostics().stop();
+        SQLTrace end = diagnostics.getTrace(true);
 
         Assert.assertNotNull(end);
         Assert.assertSame(start, end);
@@ -116,7 +116,7 @@
     @Test
     public void page10ByIndex() {
 
-        SQLTrace start = getDiagnostics().start();
+        SQLTrace start = diagnostics.getTrace();
         Assert.assertTrue(start.getEntries().isEmpty());
 
         EmployeeCriteria criteria = new EmployeeCriteria();
@@ -124,12 +124,12 @@
         criteria.setLastName(null);
         criteria.setPageSize(10);
         criteria.setPagingType(EntityPaging.Type.PAGE.name());
-        
+
         EntityPaging<Employee> paging = getRepository().getPaging(criteria);
 
         Assert.assertEquals(25, paging.size());
 
-        SQLTrace end = getDiagnostics().stop();
+        SQLTrace end = diagnostics.getTrace(true);
 
         Assert.assertNotNull(end);
         Assert.assertSame(start, end);
@@ -153,7 +153,7 @@
     @Test
     public void page10ByNext() {
 
-        SQLTrace start = getDiagnostics().start();
+        SQLTrace start = diagnostics.getTrace();
         Assert.assertTrue(start.getEntries().isEmpty());
 
         EmployeeCriteria criteria = new EmployeeCriteria();
@@ -161,12 +161,12 @@
         criteria.setLastName(null);
         criteria.setPageSize(10);
         criteria.setPagingType(EntityPaging.Type.PAGE.name());
-        
+
         EntityPaging<Employee> paging = getRepository().getPaging(criteria);
 
         Assert.assertEquals(25, paging.size());
 
-        SQLTrace end = getDiagnostics().stop();
+        SQLTrace end = diagnostics.getTrace(true);
 
         Assert.assertNotNull(end);
         Assert.assertSame(start, end);
@@ -189,6 +189,8 @@
 
     private static EntityManagerFactory emf;
 
+    private static Diagnostics diagnostics;
+
     public static EntityManagerFactory getEmf() {
         return emf;
     }
@@ -196,6 +198,8 @@
     @BeforeClass
     public static void createEMF() {
         emf = PersistenceTesting.createEMF(true);
+        diagnostics = new Diagnostics();
+        diagnostics.setEmf(emf);
 
         EntityManager em = emf.createEntityManager();
         em.getTransaction().begin();
@@ -215,14 +219,16 @@
     }
 
     private EmployeeRepository repository;
-    
+
     @Before
     public void setup() {
         this.repository = new EmployeeRepository();
         this.repository.setEntityManager(getEmf().createEntityManager());
         this.repository.getEntityManager().getTransaction().begin();
+        
+        diagnostics.clear();
     }
-    
+
     @After
     public void close() {
         this.repository.getEntityManager().getTransaction().commit();
@@ -232,9 +238,5 @@
     public EmployeeRepository getRepository() {
         return repository;
     }
-    
-    public Diagnostics getDiagnostics() {
-        return getRepository().getDiagnostics();
-    }
 
 }
diff --git a/jpa/employee/employee.model/src/test/java/eclipselink/example/jpa/employee/test/services/PageIdsInEmployeesTest.java b/jpa/employee/employee.model/src/test/java/eclipselink/example/jpa/employee/test/services/PageIdsInEmployeesTest.java
index 5d3c448..57e432d 100644
--- a/jpa/employee/employee.model/src/test/java/eclipselink/example/jpa/employee/test/services/PageIdsInEmployeesTest.java
+++ b/jpa/employee/employee.model/src/test/java/eclipselink/example/jpa/employee/test/services/PageIdsInEmployeesTest.java
@@ -26,10 +26,10 @@
 
 import eclipselink.example.jpa.employee.model.Employee;
 import eclipselink.example.jpa.employee.model.SamplePopulation;
-import eclipselink.example.jpa.employee.services.Diagnostics;
-import eclipselink.example.jpa.employee.services.Diagnostics.SQLTrace;
 import eclipselink.example.jpa.employee.services.EmployeeCriteria;
 import eclipselink.example.jpa.employee.services.EmployeeRepository;
+import eclipselink.example.jpa.employee.services.diagnostics.Diagnostics;
+import eclipselink.example.jpa.employee.services.diagnostics.Diagnostics.SQLTrace;
 import eclipselink.example.jpa.employee.services.paging.EntityPaging;
 import eclipselink.example.jpa.employee.test.PersistenceTesting;
 
@@ -44,7 +44,7 @@
     @Test
     public void page5ByIndex() {
 
-        SQLTrace start = getDiagnostics().start();
+        SQLTrace start = diagnostics.getTrace();
         Assert.assertTrue(start.getEntries().isEmpty());
 
         EmployeeCriteria criteria = new EmployeeCriteria();
@@ -57,7 +57,7 @@
 
         Assert.assertEquals(25, paging.size());
 
-        SQLTrace end = getDiagnostics().stop();
+        SQLTrace end = diagnostics.getTrace(true);
 
         Assert.assertNotNull(end);
         Assert.assertSame(start, end);
@@ -79,7 +79,7 @@
 
     @Test
     public void page5ByNext() {
-        SQLTrace start = getDiagnostics().start();
+        SQLTrace start = diagnostics.getTrace();
         Assert.assertTrue(start.getEntries().isEmpty());
 
         EmployeeCriteria criteria = new EmployeeCriteria();
@@ -91,7 +91,7 @@
 
         Assert.assertEquals(25, paging.size());
 
-        SQLTrace end = getDiagnostics().stop();
+        SQLTrace end = diagnostics.getTrace(true);
 
         Assert.assertNotNull(end);
         Assert.assertSame(start, end);
@@ -113,7 +113,7 @@
 
     @Test
     public void page10ByIndex() {
-        SQLTrace start = getDiagnostics().start();
+        SQLTrace start = diagnostics.getTrace();
         Assert.assertTrue(start.getEntries().isEmpty());
 
         EmployeeCriteria criteria = new EmployeeCriteria();
@@ -126,7 +126,7 @@
 
         Assert.assertEquals(25, paging.size());
 
-        SQLTrace end = getDiagnostics().stop();
+        SQLTrace end = diagnostics.getTrace(true);
 
         Assert.assertNotNull(end);
         Assert.assertSame(start, end);
@@ -149,7 +149,7 @@
 
     @Test
     public void page10ByNext() {
-        SQLTrace start = getDiagnostics().start();
+        SQLTrace start = diagnostics.getTrace();
         Assert.assertTrue(start.getEntries().isEmpty());
 
         EmployeeCriteria criteria = new EmployeeCriteria();
@@ -161,7 +161,7 @@
 
         Assert.assertEquals(25, paging.size());
 
-        SQLTrace end = getDiagnostics().stop();
+        SQLTrace end = diagnostics.getTrace(true);
 
         Assert.assertNotNull(end);
         Assert.assertSame(start, end);
@@ -184,6 +184,8 @@
 
     private static EntityManagerFactory emf;
 
+    private static Diagnostics diagnostics;
+
     public static EntityManagerFactory getEmf() {
         return emf;
     }
@@ -191,6 +193,8 @@
     @BeforeClass
     public static void createEMF() {
         emf = PersistenceTesting.createEMF(true);
+        diagnostics = new Diagnostics();
+        diagnostics.setEmf(emf);
 
         EntityManager em = emf.createEntityManager();
         em.getTransaction().begin();
@@ -216,6 +220,8 @@
         this.repository = new EmployeeRepository();
         this.repository.setEntityManager(getEmf().createEntityManager());
         this.repository.getEntityManager().getTransaction().begin();
+        
+        diagnostics.clear();
     }
 
     @After
@@ -228,8 +234,4 @@
         return repository;
     }
 
-    public Diagnostics getDiagnostics() {
-        return getRepository().getDiagnostics();
-    }
-
 }
diff --git a/jpa/employee/employee.web/src/main/java/eclipselink/example/jpa/employee/web/Admin.java b/jpa/employee/employee.web/src/main/java/eclipselink/example/jpa/employee/web/Admin.java
index 6267a30..3e75548 100644
--- a/jpa/employee/employee.web/src/main/java/eclipselink/example/jpa/employee/web/Admin.java
+++ b/jpa/employee/employee.web/src/main/java/eclipselink/example/jpa/employee/web/Admin.java
@@ -46,11 +46,13 @@
     }
 
     public String resetDatabase() {
-        return getAdminBean().resetDatabase();
+        getAdminBean().resetDatabase();
+        return null;
     }
 
     public String populateDatabase() {
-        return getAdminBean().populateDatabase(25);
+        getAdminBean().populateDatabase(25);
+        return null;
     }
 
     public List<String> getTypeNames() {
diff --git a/jpa/employee/employee.web/src/main/java/eclipselink/example/jpa/employee/web/DiagnosticsTrace.java b/jpa/employee/employee.web/src/main/java/eclipselink/example/jpa/employee/web/DiagnosticsTrace.java
new file mode 100644
index 0000000..715aa28
--- /dev/null
+++ b/jpa/employee/employee.web/src/main/java/eclipselink/example/jpa/employee/web/DiagnosticsTrace.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the 
+ * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 
+ * which accompanies this distribution. 
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at 
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *  dclarke - initial
+ ******************************************************************************/
+package eclipselink.example.jpa.employee.web;
+
+import javax.ejb.EJB;
+import javax.faces.application.FacesMessage;
+import javax.faces.bean.ManagedBean;
+import javax.faces.bean.RequestScoped;
+import javax.faces.context.FacesContext;
+
+import eclipselink.example.jpa.employee.services.diagnostics.Diagnostics;
+import eclipselink.example.jpa.employee.services.diagnostics.Diagnostics.SQLTrace;
+
+/**
+ * TODO
+ * 
+ * @author dclarke
+ * @since EclipseLink 2.4.2
+ */
+@ManagedBean
+@RequestScoped
+public class DiagnosticsTrace {
+
+    private Diagnostics diagnostics;
+
+    public Diagnostics getDiagnostics() {
+        return diagnostics;
+    }
+
+    @EJB
+    public void setDiagnostics(Diagnostics diagnostics) {
+        this.diagnostics = diagnostics;
+    }
+
+    public String getMessages() {
+        SQLTrace trace = getDiagnostics().getTrace(true);
+
+        if (trace != null) {
+            for (String entry : trace.getEntries()) {
+                FacesContext.getCurrentInstance().addMessage("SQL", new FacesMessage(entry));
+            }
+        }
+        return null;
+    }
+
+}
diff --git a/jpa/employee/employee.web/src/main/java/eclipselink/example/jpa/employee/web/EditEmployee.java b/jpa/employee/employee.web/src/main/java/eclipselink/example/jpa/employee/web/EditEmployee.java
index 0daf8d6..1fce81b 100644
--- a/jpa/employee/employee.web/src/main/java/eclipselink/example/jpa/employee/web/EditEmployee.java
+++ b/jpa/employee/employee.web/src/main/java/eclipselink/example/jpa/employee/web/EditEmployee.java
@@ -23,7 +23,6 @@
 import eclipselink.example.jpa.employee.model.Address;
 import eclipselink.example.jpa.employee.model.Employee;
 import eclipselink.example.jpa.employee.model.PhoneNumber;
-import eclipselink.example.jpa.employee.services.Diagnostics.SQLTrace;
 import eclipselink.example.jpa.employee.services.EmployeeRepository;
 
 /**
@@ -46,6 +45,7 @@
 
     protected static final String PAGE = "/employee/edit";
     protected static final String PAGE_REDIRECT = "/employee/edit?faces-redirect=true";
+    protected static final String INDEX_PAGE = "/index?faces-redirect=true";
 
     public EmployeeRepository getRepository() {
         return repository;
@@ -61,9 +61,7 @@
         Flash flashScope = FacesContext.getCurrentInstance().getExternalContext().getFlash();
         this.employee = (Employee) flashScope.get("employee");
 
-        if (this.employee != null) {
-            refresh();
-        } else {
+        if (this.employee == null) {
             this.employee = new Employee();
             this.employee.setAddress(new Address());
         }
@@ -74,7 +72,7 @@
     }
 
     public String getEmployeeId() {
-        if (getEmployee().getId() <= 0) {
+        if (getEmployee() == null || getEmployee().getId() <= 0) {
             return "None Assigned";
         }
         return Integer.toString(getEmployee().getId());
@@ -97,9 +95,7 @@
      * @return
      */
     public String save() {
-        startSqlCapture();
         Employee emp = getRepository().save(getEmployee());
-        stopSqlCapture();
         if (emp == null) {
             FacesContext.getCurrentInstance().addMessage("OptimisticLockException", new FacesMessage("Commit Failed: Lock Exception or Entity Deleted."));
         } else {
@@ -110,29 +106,21 @@
     }
 
     public String delete() {
-        startSqlCapture();
-        getRepository().delete(getEmployee());
-        stopSqlCapture();
+        this.employee = getRepository().delete(getEmployee());
         return cancel();
     }
 
     public String refresh() {
-        startSqlCapture();
-        
         this.employee = getRepository().refresh(getEmployee());
         if (this.employee == null) {
             return cancel();
         }
-        getEmployee().getAddress();
-        getEmployee().getPhoneNumbers().size();
-        
-        stopSqlCapture();
-        
+
         return null;
     }
 
     public String cancel() {
-        return "/index?faces-redirect=true";
+        return INDEX_PAGE;
     }
 
     /**
@@ -140,9 +128,7 @@
      * operations will fail.
      */
     public String updateVersion() {
-        startSqlCapture();
         int newVersion = getRepository().updateVersion(getEmployee());
-        stopSqlCapture();
 
         FacesContext.getCurrentInstance().addMessage("Update version", new FacesMessage("DATABASE EMPLOYEE ID: " + getEmployee().getId() + " VERSION= " + newVersion));
 
@@ -174,22 +160,4 @@
         return null;
     }
 
-    protected void startSqlCapture() {
-        addMessages(getRepository().getDiagnostics().start());
-    }
-
-    protected void stopSqlCapture() {
-        addMessages(getRepository().getDiagnostics().stop());
-    }
-
-    /**
-     * Add each SQL string to the messages TODO: Allow this to be
-     * enabled/disabled
-     */
-    private void addMessages(SQLTrace sqlTrace) {
-        for (String entry : sqlTrace.getEntries()) {
-            FacesContext.getCurrentInstance().addMessage("SQL", new FacesMessage(entry));
-        }
-    }
-
 }
diff --git a/jpa/employee/employee.web/src/main/java/eclipselink/example/jpa/employee/web/EditEmployeeView.java b/jpa/employee/employee.web/src/main/java/eclipselink/example/jpa/employee/web/EditEmployeeView.java
deleted file mode 100644
index 07991d7..0000000
--- a/jpa/employee/employee.web/src/main/java/eclipselink/example/jpa/employee/web/EditEmployeeView.java
+++ /dev/null
@@ -1,185 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010-2013 Oracle. All rights reserved.
- * This program and the accompanying materials are made available under the 
- * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 
- * which accompanies this distribution. 
- * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at 
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
- *  dclarke - EclipseLink 2.3 - MySports Demo Bug 344608
- ******************************************************************************/
-package eclipselink.example.jpa.employee.web;
-
-import javax.annotation.PostConstruct;
-import javax.ejb.EJB;
-import javax.faces.application.FacesMessage;
-import javax.faces.bean.ManagedBean;
-import javax.faces.bean.ViewScoped;
-import javax.faces.context.FacesContext;
-import javax.faces.context.Flash;
-import javax.persistence.OptimisticLockException;
-
-import eclipselink.example.jpa.employee.model.Address;
-import eclipselink.example.jpa.employee.model.Employee;
-import eclipselink.example.jpa.employee.model.PhoneNumber;
-import eclipselink.example.jpa.employee.services.Diagnostics;
-import eclipselink.example.jpa.employee.services.Diagnostics.SQLTrace;
-import eclipselink.example.jpa.employee.services.EmployeeRepository;
-
-/**
- * Backing bean to edit or create an {@link Employee}.
- * 
- * @author dclarke
- * @since EclipseLink 2.4.2
- */
-@ManagedBean
-@ViewScoped
-public class EditEmployeeView {
-
-    private EmployeeRepository repository;
-
-    private Employee employee;
-
-    /**
-     * Value used to create new unique {@link PhoneNumber}
-     */
-    private String type;
-
-    protected static final String PAGE = "/employee/edit";
-    protected static final String PAGE_REDIRECT = "/employee/edit?faces-redirect=true";
-
-    @PostConstruct
-    private void init() {
-        Flash flashScope = FacesContext.getCurrentInstance().getExternalContext().getFlash();
-        Integer id = (Integer) flashScope.get("employee-id");
-        setEmployee(id);
-    }
-
-    public EmployeeRepository getRepository() {
-        return repository;
-    }
-
-    @EJB
-    public void setRepository(EmployeeRepository repository) {
-        this.repository = repository;
-    }
-
-    public Employee getEmployee() {
-        return this.employee;
-    }
-
-    public void setEmployee(int id) {
-        getDiagnostics().start();
-        this.employee = getRepository().find(id);
-
-    }
-
-    public String getEmployeeId() {
-        if (getEmployee().getId() <= 0) {
-            return "None Assigned";
-        }
-        return Integer.toString(getEmployee().getId());
-    }
-
-    public String getType() {
-        return type;
-    }
-
-    public void setType(String type) {
-        this.type = type;
-    }
-
-    public boolean isCreate() {
-        return getEmployee() != null && getEmployee().getId() <= 0;
-    }
-
-    public Diagnostics getDiagnostics() {
-        return getRepository().getDiagnostics();
-    }
-
-    /**
-     * 
-     * @return
-     */
-    public String save() {
-        try {
-            getDiagnostics().start();
-            getRepository().save(getEmployee());
-        } catch (OptimisticLockException e) {
-            FacesContext.getCurrentInstance().addMessage("EclipseLink", new FacesMessage("OptimisticLockException: Could not save changes"));
-        } finally {
-            stopSqlCapture();
-        }
-        return null;
-    }
-
-    public String delete() {
-        getDiagnostics().start();
-        getRepository().delete(getEmployee());
-        stopSqlCapture();
-        return cancel();
-    }
-
-    public String refresh() {
-        getDiagnostics().start();
-        this.employee = getRepository().refresh(getEmployee());
-        stopSqlCapture();
-        return null;
-    }
-
-    public String cancel() {
-        return "/index?faces-redirect=true";
-    }
-
-    /**
-     * Force the optimistic version field to be updated so that the save
-     * operations will fail.
-     */
-    public String updateVersion() {
-        getDiagnostics().start();
-        getRepository().updateVersion(getEmployee());
-        stopSqlCapture();
-        return null;
-    }
-
-    public Address getAddress() {
-        return getEmployee().getAddress();
-    }
-
-    public String removeAddress() {
-        getEmployee().setAddress(null);
-        return null;
-    }
-
-    public String addAddress() {
-        getEmployee().setAddress(new Address());
-        return null;
-    }
-
-    public String addPhone() {
-        PhoneNumber newPhone = getRepository().addPhone(getEmployee(), getType());
-        if (newPhone == null) {
-            FacesContext.getCurrentInstance().addMessage("input", new FacesMessage("Invalid type. Phone number could not be added"));
-        }
-        setType("");
-        return null;
-    }
-
-    public String remove(PhoneNumber phone) {
-        getEmployee().removePhoneNumber(phone);
-        return null;
-    }
-
-    protected void stopSqlCapture() {
-        addMessages(getRepository().getDiagnostics().stop());
-    }
-
-    private void addMessages(SQLTrace sqlTrace) {
-        for (String entry : sqlTrace.getEntries()) {
-            FacesContext.getCurrentInstance().addMessage("SQL", new FacesMessage(entry));
-        }
-    }
-
-}
diff --git a/jpa/employee/employee.web/src/main/java/eclipselink/example/jpa/employee/web/EmployeeResults.java b/jpa/employee/employee.web/src/main/java/eclipselink/example/jpa/employee/web/EmployeeResults.java
index 2e4420c..9ca6b7d 100644
--- a/jpa/employee/employee.web/src/main/java/eclipselink/example/jpa/employee/web/EmployeeResults.java
+++ b/jpa/employee/employee.web/src/main/java/eclipselink/example/jpa/employee/web/EmployeeResults.java
@@ -16,14 +16,12 @@
 
 import javax.annotation.PostConstruct;
 import javax.ejb.EJB;
-import javax.faces.application.FacesMessage;
 import javax.faces.bean.ManagedBean;
 import javax.faces.bean.ViewScoped;
 import javax.faces.context.FacesContext;
 import javax.faces.context.Flash;
 
 import eclipselink.example.jpa.employee.model.Employee;
-import eclipselink.example.jpa.employee.services.Diagnostics.SQLTrace;
 import eclipselink.example.jpa.employee.services.EmployeeCriteria;
 import eclipselink.example.jpa.employee.services.EmployeeRepository;
 import eclipselink.example.jpa.employee.services.paging.EntityPaging;
@@ -76,16 +74,9 @@
         this.employees = null;
 
         this.paging = getRepository().getPaging(criteria);
-
-        if (!hasPaging()) {
-            startSqlCapture();
-
-            stopSqlCapture();
-        }
     }
 
     public List<Employee> getEmployees() {
-        startSqlCapture();
         if (this.employees == null) {
             if (hasPaging()) {
                 this.employees = getPaging().get(this.currentPage);
@@ -93,7 +84,6 @@
                 this.employees = getRepository().getEmployees(criteria);
             }
         }
-        stopSqlCapture();
         return this.employees;
     }
 
@@ -150,22 +140,4 @@
         return EditEmployee.PAGE;
     }
 
-    protected void startSqlCapture() {
-        addMessages(getRepository().getDiagnostics().start());
-    }
-
-    protected void stopSqlCapture() {
-        addMessages(getRepository().getDiagnostics().stop());
-    }
-
-    /**
-     * Add each SQL string to the messages TODO: Allow this to be
-     * enabled/disabled
-     */
-    private void addMessages(SQLTrace sqlTrace) {
-        for (String entry : sqlTrace.getEntries()) {
-            FacesContext.getCurrentInstance().addMessage("SQL", new FacesMessage(entry));
-        }
-    }
-
 }
diff --git a/jpa/employee/employee.web/src/main/webapp/WEB-INF/template.jsf b/jpa/employee/employee.web/src/main/webapp/WEB-INF/template.jsf
index bed3307..f6a94e9 100644
--- a/jpa/employee/employee.web/src/main/webapp/WEB-INF/template.jsf
+++ b/jpa/employee/employee.web/src/main/webapp/WEB-INF/template.jsf
@@ -47,7 +47,7 @@
 
 			</div>
 		</div>
-
+		<h:outputText value="#{diagnosticsTrace.messages}" />
 		<div id="footer-container">
 			<footer class="wrapper"> <h:messages /> </footer>
 		</div>
diff --git a/jpa/employee/employee.web/src/main/webapp/employee/edit.xhtml b/jpa/employee/employee.web/src/main/webapp/employee/edit.xhtml
index 949f03d..53496dd 100644
--- a/jpa/employee/employee.web/src/main/webapp/employee/edit.xhtml
+++ b/jpa/employee/employee.web/src/main/webapp/employee/edit.xhtml
@@ -25,7 +25,7 @@
 				<h:panelGrid width="600" columns="2" border="1" class="table-design">
 					<f:facet name="header">Employee</f:facet>
 					<h:outputLabel value="ID:" />
-					<h:outputLabel value="#{editEmployee.employee.id}" />
+					<h:outputLabel value="#{editEmployee.employeeId}" />
 					<h:outputLabel value="First Name:" />
 					<h:inputText value="#{editEmployee.employee.firstName}" />
 					<h:outputLabel value="Last Name:" />
diff --git a/jpa/employee/employee.web/src/main/webapp/index.xhtml b/jpa/employee/employee.web/src/main/webapp/index.xhtml
index d17a179..1b7c01e 100644
--- a/jpa/employee/employee.web/src/main/webapp/index.xhtml
+++ b/jpa/employee/employee.web/src/main/webapp/index.xhtml
@@ -35,17 +35,6 @@
 					</div>
 				</h:panelGroup>
 			</h:panelGrid>
-			<p />
-			<h:panelGrid width="600" columns="1" class="table-design">
-				<f:facet name="header">Projects</f:facet>
-				<h:panelGroup>
-					<h3>Searches</h3>
-					<ul>
-					</ul>
-				</h:panelGroup>
-				<h:commandLink action="/employee/edit?faces-redirect=true"
-					value="Create" />
-			</h:panelGrid>
 		</h:form>
 	</ui:define>