JpaRepository的native insert

实例

public interface UserRoleDao extends JpaRepository {

    @Modifying
    @Query(value = "INSERT INTO user_role (id, userid,roleid) " +
            "VALUES (func_nextid('user_role'),?1, ?2)", nativeQuery=true)
    void insert(Long userId, Integer roleId);
}

加上transaction调用

@Test
    @Transactional("demoTransactionManager")
    public void testInsert(){
        Long rs = userRoleDao.insert(232L,123);
        System.out.println("result:"+rs);
    }

你可能感兴趣的:(springboot)