native insert query in hibernate + spring data

前端 未结 2 1941
北海茫月
北海茫月 2020-12-18 21:41

I try to add the following code to a spring data jpa repository:

  @Query(\"insert into commit_activity_link (commit_id, activity_id) VALUES (?1, ?2)\")
  vo         


        
相关标签:
2条回答
  • 2020-12-18 21:59

    I had to add nativeQuery = true to @Query

    @Query(value = "insert into commit_activity_link (commit_id, activity_id) VALUES (?1, ?2)", nativeQuery = true)
    
    0 讨论(0)
  • 2020-12-18 22:14

    Use java object rather passing all parameters

    @Modifying(clearAutomatically = true)
        @Transactional
        @Query(value = "insert into [xx_schema].[shipment_p] (gpn,qty,hscode,country_of_origin,created_date_time,shipment_id) "
                + "VALUES (:#{#sp.gpn},:#{#sp.qty},  :#{#sp.hscode} ,:#{#sp.countryOfOrigin}, :#{#sp.createdDateTime}, :#{#sp.id} )", nativeQuery = true)
        public void saveShipmentPRoducts(@Param("sp") ShipmentProducts sp);
    
    0 讨论(0)
提交回复
热议问题