|
Currently native queries for MongoDB are expressed like this:
String nativeQuery = "{ $and: [ { name : 'Portia' }, { author : 'Oscar Wilde' } ] }";
Query query = em.createNativeQuery( nativeQuery, OscarWildePoem.class );
While this works for basic cases, there are some limitations:
-
projections can't be expressed
-
offset/limit can't be expressed
(The reason being that MongoDB has no "full" query language which would accept all required elements in one String, instead the different parts are to be passed as individual parameters to the driver API).
This could be avoided by accepting an "invocation" of MongoDB's JS find() API:
String nativeQuery = "db.Poem.find("
+ "{ $and: [ { name : 'Portia' }, { author : 'Oscar Wilde' } ] }," + "{_id : 1, name : 1})." + "skip(100).limit(100)";
This would allow to retrieve the collection name from the actual query (today we derive it from the one and only entity result type set, which I believe gets semantics kind of backwards).
Scalar values could be mapped via SqlResultSetMapping/ColumnResult.
|