对于Query类型,方法getLong()未定义

时间:2013-03-26 15:50:56

标签: jdbc persistence openjpa

当我在JPA中编码时,我发现此错误说“查询类型的方法getLong()未定义”请帮我解决这个问题。

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;}

1 个答案:

答案 0 :(得分:0)

错误告诉您没有为javax.persistence.Query接口定义getLong()。也许你的意思是:

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