开发者

problem with named parameter query in hibernate

开发者 https://www.devze.com 2023-02-04 04:29 出处:网络
In order to prevent SQL Injection i am trying to convert dynamic queries to named parameter query.. however, when i am using this code -

In order to prevent SQL Injection i am trying to convert dynamic queries to named parameter query.. however, when i am using this code -

String query = "from Ad a left join fetch a.adQueries left join fetch a.aduser u left join fetch u.profile where a.id =:identifier";
        Query q = s.createQuery(query);
        q.setParameter("identi开发者_如何学Pythonfier", id);

No data is returned from DB even though the data is there and the same query in dynamic form return data

and when i use this code -

String query = "from Ad a left join fetch a.adQueries left join fetch a.aduser u left join fetch u.profile where a.id =:identifier";
        Query q = s.createQuery(query);
        q.setLong("identifier", id);

it throws a Null pointer exception..

Please let me know where i am going wrong

Thanks


Perhaps id is null, it can cause such a behaviour.

0

精彩评论

暂无评论...
验证码 换一张
取 消