Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 3rd, 2012  |  syntax: None  |  size: 0.69 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public List<Product> findAllProducts(){
  2.         Query query = null;
  3.         List<Product> products = null;
  4.         try {
  5.             Context ctx = (Context) new javax.naming.InitialContext().lookup("java:comp/env");
  6.             utx.begin();
  7.             EntityManager em = (EntityManager) ctx.lookup("persistence/LogicalName");
  8.            
  9.             query = em.createQuery("SELECT * FROM CUSTOMERS");
  10.             products = query.getResultList();
  11.            
  12.             utx.commit();
  13.         } catch(Exception e) {
  14.             Logger.getLogger(getClass().getName()).log(Level.SEVERE,"exception caught", e);
  15.             throw new RuntimeException(e);
  16.         }
  17.         return products;
  18.     }