Native Queries would have you implement a match(Object o) method in Java that is then used to create a SQL select statement. Byte-code analysis of your method is used to convert the method's logic into a query usable your favorite ORM library. What's great about this is that you don't have to learn a new query language, and that it's all checked at compile-time and you can even do IDE refactoring.
As an example, HQL (the hibernate query language) is parsed, etc at runtime so syntax or variables are not checked until runtime. Hibernate has "criteria queries" that avoid the issue of syntax by having classes/methods that represent all the different possible operators. But you still have to pass in properties as strings (e.g. Expression.like("firstName", nameQuery)).
Implementing native queries could be difficult, but even a simple implementation that permits only very basic operations could cover a vast majority of cases. For example, permit basic operators and the use of methods and variables in the model class, but don't permit execution of any other code. If your query logic was complex you wouldn't want to use this approach anyway but would directly use the ORM query language or SQL.
It looks like the POJQ library has an implementation for JDO and could be extended for other ORM libraries. There is also a db4o project which has a much broader scope and seems somewhat "closed" although under an open license. The API requires a login to find, so if you're curious you can find it here.
No Comments/Pingbacks for this post yet...