我的命名查询:
@NamedQuery(name = "EmsDetails.findAll", query = "SELECT e FROM EmsDetails e")
private static Logger logger = Logger.getLogger(EmsDetailsDTO.class);
EntityManagerFactory emf = Persistence.createEntityManagerFactory("Employee_Mangement_SystemPU");
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
public List<EmsDetails> getAllEMSDetails() {
List<EmsDetails> emsDetails = em.createNamedQuery("EmsDetails.findAll").getResultList();
logger.info(emsDetails.size());
for(EmsDetails e : emsDetails){
logger.info(e.getAddress());
}
return getAllEMSDetails();
}
public boolean addEmployee(EmsDetails detail){
tx.begin();
em.persist(detail);
tx.commit();
return true;
}
public void closeEM(){
em.close();
emf.close();
}
public static void main(String[] args) {
EmsDetailsDTO e = new EmsDetailsDTO();
e.getAllEMSDetails();
}
结果:
4:55:36,660 INFO EmsDetailsDTO:28 - 1
14:55:36,670 INFO EmsDetailsDTO:30 - I
14:55:36,670 INFO EmsDetailsDTO:28 - 1
14:55:36,670 INFO EmsDetailsDTO:30 - I
14:55:36,670 INFO EmsDetailsDTO:28 - 1
14:55:36,670 INFO EmsDetailsDTO:30 - I
使用 JPA (eclipselink) 时,结果循环到无穷大。