Issue
I am trying to run an insert native query similar to the following
INSERT INTO t3(t1,t2)
SELECT t1.c1,sum(t1.c2) table1 t1 WHERE t1.c3 = 'something'
GROUP BY t1;
I am calling it using a repository and the system actually runs the query without any error. However, no value is being inserted. The query works when I try to run using the database interface.
Solution
I was able to make it work. My mistake was not using @Modifying
annotation on top of the function. I was simple using @Transactional only. If you require more then one table to be impacted simultaneously then use the annotation as well. It got the job done for me. exapme snippet below
@Transactional
@Modifying
@Query(value = Query.YOUR_QUERY, nativeQuery = true)
void insert(@Param("param") var param1);
Answered By - PKS
Answer Checked By - Gilberto Lyons (JavaFixing Admin)