1. Add a NamedQuery to the class: @NamedQueries{( @NamedQuery (name = "Note.listAll", query = "SELECT n FROM Note n") )}
2. Use JPA code like this: List<Note> listAll { em = getEntityManager(); List<Note> theList = null; try { Query q = em.createNamedQuery("Note.listAll"); theList = q.getResultList(); Collections.sort(theList); } catch (Exception e) { java.util.logging.Logger.getLogger(getClass().getName()).log (java.util.logging.Level.SEVERE, "exception caught", e); throw new RuntimeException(e); } finally { em.close(); } return(theList); } 3. The key point is that the entity class and JPA operate on single records On Apr 13, 2009, at 12:04 PM, Coonay wrote: > > import javax.persistence.Entity > > @Entity > public class Note implements IsSerializable { > @Id > @GeneratedValue(strategy = GenerationType.IDENTITY) > private Long id; > private String notePoster; > } > > what is the simple method(simple means the least code) to get the all > records for entity Note using JPA API? > > Note:some api calling like Note.all() is what i expect, > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Java EE (J2EE) Programming with Passion!" group. To post to this group, send email to java-ee-j2ee-programming-with-passion@googlegroups.com To unsubscribe from this group, send email to java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en -~----------~----~----~----~------~----~------~--~---