我在 JPA 中有以下代码,用于在使用本机查询插入后返回自动生成的 ID:
Query q = em.createNativeQuery("insert into .... returning ID", Long.class);
q.executeUpdate();
但是,我收到以下错误:
A result was returned when none was expected
好吧,这很简单。我刚刚使用了 q.getSingleResults() 并且效果很好!
Query q = em.createNativeQuery(sql);
BigInteger biid = (BigInteger) q.getSingleResult();
long id = biid.longValue();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)