0

I have a table say it Name(name,lock,timestamp). name column is Primary key and for inserting i am not using inbuilt save method with does insert/update. My Requirement is to just insert and not to update if there exist. so I wrote my custom query for inserting data. When i run the query it inserts data into table but throws exception saying Caused by: com.edb.util.PSQLException: No results were returned by the query.

I tried using my custom insert with with constraint on confict.

@Repository
public interface MyNameRepository extends JpaRepository<MyEntity, Long> {

    @Query(value="INSERT into name(name,lock,updtedTime) values (?,?,?) on conflict ON CONSTRAINT unique_name do nothing",nativeQuery = true)
    public void insertData(String name,int lock,Timestamp startTime);
}

I expect it should insert without any error.

  • Try `@Modifying` on your `insertData` method – crizzis Oct 08 '19 at 20:26
  • Possible duplicate of [updating boolean value in spring data jpa using @Query, with hibernate](https://stackoverflow.com/questions/10220262/updating-boolean-value-in-spring-data-jpa-using-query-with-hibernate) – Jens Schauder Oct 08 '19 at 21:39

0 Answers0