Search code examples
jdbcpersistenceopenjpa

The method getLong() is undefined for the type Query


when i was coding in JPA , i found this error saying "The method getLong() is undefined for the type Query" please help me out wit resolving this .

public long getErrorid(String errDesc)
{long errorid=0;
EntityManagerFactory entityManagerFactory =  Persistence.createEntityManagerFactory("wqs-poc"); System.out.println("EntityManager Factory created successfully !!!");
    EntityManager em = entityManagerFactory.createEntityManager();
    System.out.println("eNTITYmANAGER CREATED SUCCESSFLLY !!!"); Query query = em.createNativeQuery("SELECT errorid FROM wqsd.error_master WHERE errdsesc = "+errorid); errorid  = (long)query.getLong();
    System.out.println("errorid= "+errorid);
    return errorid;}

Solution

  • The error is telling you that getLong() isn't defined for the javax.persistence.Query interface. Perhaps you meant :

    errorid = (Long)query.getSingleResult()[0];