根据我阅读的许多文章,当我使用JPA/Hibernate查询时,最好在查询中设置参数,以避免SQL注入。例如:
select user from User user where user.name = :name and user.surname = :surname
我的问题在于,在某些情况下,我需要在创建查询时使用本地查询。
我会使用实体管理器和createNativeQuery
。但在这种情况下,参数将是位置参数。例如:
select * from users where user_name = ? and user_surname = ?
那么在我的查询中,我将使用setParameter(1, "name")
等方法。那么这种情况是否像参数化查询一样是“SQL注入防护”呢?