Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

JPA Query langauge

by using JPA Query i want to get the list of users whose id is 3, but my problem is that three times getting same results, what is the wrong with this code?

@Override
public List<User_Dept> findAll(long myId) {

    EntityManager em = entityManagerFactory.createEntityManager();
    Query query = em.createQuery("SELECT u FROM User_Dept u WHERE u.user_id = :userId");
    query.setParameter("userId", myId);
    List<User_Dept> resultList = query.getResultList();
    resultList.forEach(System.out::println);
    logger.info("resultList " + resultList);
    Iterator<User_Dept> itr = resultList.iterator();
    while (itr.hasNext()) {
        User_Dept uds = itr.next();
        logger.info(uds.getDept_id());
    }
    em.close();
    return resultList;
}

in my DB table there are 3 users whose id is 3.

Comments