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.