开发者

store dynamic JPA Queries

In a webproject i have a complex form to build a dynamic query. When i wrote this code I only had JPA 1, (no Criteria API) so i build the query String dynamicly (but still use bind parameters). This works fine so far. Now i want to save the Query (not the result) so the user can re-run the same query later.

Idealisticaly, i would just store the query string in the db. While constructing the query, i could make sure only using the IDs (not "where user = :user" but "where user.id = :userid").

As the input to the parameters comes from the user, i like to use query parameters, to avoid 'little bobby tables'.

Is there an ea开发者_高级运维sy way to do this?


I'm not sure why this is a problem because I see no reason for you to just make a table to store the queries in. The tricky part must be in 1) Getting the available parameters from somewhere. Maybe you can store that in a parameters table if needed. 2) Deciding which parameters to set. Just find all :parameters in the query query, see if you got that parameter available and set it on the query.

What am I missing?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜