users@glassfish.java.net

Re: how to create dynamic where clause in ejbql of jpa/toplink essentials

From: <glassfish_at_javadesktop.org>
Date: Tue, 09 Oct 2007 10:35:32 PDT

Well, you're at an impasse then.

You need to talk to your lead and see what they suggest as a solution.

You can put fragments of SQL/EQL in to, say, a ResourceBundle, and then write your code to stich together the fragments at runtime.

Or you could name your queries in some composable fashion and simply create all of the permutations necessary. Then you at run time build up the label of the SQL you want, and then fetch it from the resource bundle. That way you're assembling the logical name of the query, rather than the query itself.

This would be spectacularly ugly on a complex query, but it does keep all of the SQL out of your code.

Technically, embedding a WHERE clause in to the program and tacking it on to a static SQL/EQL statement violates the "no sql's in code" edict, as it puts in to the code knowledge of the SQL statement (you need to know where to merge in the WHERE clause, for example).

So, really, this is a matter between you and your lead.
[Message sent by forum member 'whartung' (whartung)]

http://forums.java.net/jive/thread.jspa?messageID=239160