java.sql.SQLException: sql injection violation, part alway true condition not allow

java.sql.SQLException: sql injection violation, part alway true condition not allow : 
    select * from student where gender = 1 and 1 = 1 and grade = 6;

    at com.alibaba.druid.wall.WallFilter.check(WallFilter.java:671)
    at com.alibaba.druid.wall.WallFilter.connection_prepareStatement(WallFilter.java:214)

    错误内容是druid的sql防火墙报警,发现是hibernate自动拼接了1=1的永真条件,而druid只会放行排在第一的永真条件,查看hibernate源代码后发现,当引用Junction生成sql时,如果条件为空,则会自动拼接1=1的永真条件。

    解决办法也很简单,修改自己的代码,将引用junction的条件拼接放在第一位即可。

你可能感兴趣的:(Exception)