最后插入的ID,泽西岛返回0

时间:2014-04-20 17:07:48

标签: java mysql jpa jersey

我有一个服务从我的mysql数据库返回last_insert_id但是我总是得到0作为响应。 问题是什么?

服务代码:

@GET
@Produces("text/plain")
@Path("lastindex")
public int getLastInsertKey() {

    Query q = getEntityManager().createNativeQuery("select last_insert_id() as lastindex");
    lastIndex= q.getFirstResult();
    return lastIndex;
}

0 个答案:

没有答案
相关问题