【问题标题】:Hibernate and SQL injection休眠和 SQL 注入
【发布时间】:2017-07-26 07:30:13
【问题描述】:

我已经看到一些讨论通过命名参数来防止 SQL 注入的主题,但是 hibernate 语句怎么样

currentSession().update(object);

或

currentSession().save(object)?

这些安全吗?或者总是使用命名参数更安全,比如

currentSession().createQuery("update Object set field=:field where id=:id").setParameter("field", field).setParameter("id", id).executeUpdate()?

【问题讨论】:

    标签: java hibernate sql-injection


    【解决方案1】:

    它们是安全的,Hibernate 将绑定变量用于实体 CRUD 语句。为每个实体缓存语句,以避免每次需要时都创建它们,并且在执行时只提供绑定的变量值。

    您可以enable SQL logging查看生成的SQL。

    【讨论】:

      猜你喜欢
      • 2013-10-19
      • 1970-01-01
      • 2013-05-24
      • 2020-03-24
      • 2016-07-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多