Entity Bean-2 Fetch All Data
package mypack;
import java.util.Iterator;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Query;
public class FetchAll {
public static void main(String[] args) {
EntityManagerFactory f=GetEntity.getManagerFactory();
EntityManager em=GetEntity.getEntityManager();
//EntityTransaction t=em.getTransaction();
//t.begin();
Query q=em.createQuery("select e from Emp e where id=?");
List<Emp> list= q.getResultList();
Iterator<Emp> itr=list.iterator();
System.out.println("Id\tName\tAddress\tEmail\tSalary");
while(itr.hasNext()){
Emp e=itr.next();
System.out.println(e.getId()+"\t"+e.getName()
+"\t"+e.getAddress()+"\t"+e.getEmail()+"\t"+e.getSalary());
}
// t.commit();
em.close();
}
}