Skip to content Skip to sidebar Skip to footer

How To Use Jpa Query To Insert Data Into Db?

I have a problem with my prepared statement but i can not figure out where the error is. I am trying to insert a URI link into the database. @Repository public interface LoggerDa

Solution 1:

I managed to solve the issue. I added an id to the parameters so that i can pass in the id of the user, using Principal in the controller.

@Repository
public interface LoggerDao extends CrudRepository<Logger, Long> {
    @Query("select t from Logger t where t.user.id=?#{principal.id}")
    List<Logger> findAll();

    @Modifying
    @Query(value = "insert into Logger (redirect,user_id) VALUES (:insertLink,:id)", nativeQuery = true)
    @Transactional
    void logURI(@Param("insertLink") String insertLink, @Param("id") Long id);

Post a Comment for "How To Use Jpa Query To Insert Data Into Db?"