SQL injection prevention with hibernate

前端 未结 2 576
予麋鹿
予麋鹿 2021-01-26 00:33

I have a existing code where the application generates different sql depend of lot of conditions and execute them via hibernate sessions createSQLQuery(). In here the parameters

2条回答
  •  清歌不尽
    2021-01-26 01:00

    As far as I can tell, you want to create SQL queries on the fly because the combination of conditions (from the UI, I guess) can be very complicated. That's fine. All you need to control are the parameters that the user supplies. And for that, you can, and should, still use Hibernate's createSqlQuery(). That function understands either ? for positional parameters (numbered from beginning of query string), or :param_name syntax and then you supply named parameters. You don't need to move anything into an xml file.

    Section 16.1.7 has examples.

提交回复
热议问题