我有两个表city和shape,其中city具有复合主键(City和country)和一个自动生成的ID值。此Id是Shape的外键。所以在城市表中插入数据后,我希望插入的Id在形状表中使用。我在jpa和postgres中使用了Spring boot
在CityRepository中,我有自定义的保存方法,它不会对冲突做任何事情。
我已经尝试了下面的代码来获取返回值。但我得到了错误SqlExceptionHelper :返回了一个结果,而不是预期的结果。
如何从insert查询获取返回值?
@Modifying
@Query(value="insert into public.city_info(city, country) values(:city,:country) on conflict do nothing returning city_id",nativeQuery = true)
@Transactional
Integer save(@Param("city")String city,@Param("country") String country);发布于 2018-08-07 22:03:06
我很担心,但这在JPA中是不可能的。
如果您查看JPA查询API:
int executeUpdate()
Execute an update or delete statement.
Returns: the number of entities updated or deleted没有其他可能的返回值。
https://stackoverflow.com/questions/51723350
复制相似问题