-2

Does Datanucleus JPA have support for MongoDB

For example:

entityManager.createNativeQuery("db.Movie.find()");
enkor
  • 7,527
  • 3
  • 31
  • 55
  • 1
    http://www.datanucleus.org/products/accessplatform_3_0/datastore_features.html – Konstantin V. Salikhov Sep 10 '14 at 08:55
  • Thanks for your reply @KonstantinV.Salikhov. I tried it but it is returning null and not throwing any exception. So i need to know whether it can be done or not. – Ramesh Manly Sep 10 '14 at 09:08
  • Why not just do a JPQL query of "SELECT m FROM Movie m"? what do you think that would execute behind the scenes ? assuming you aren't actually looking at the log which tells you –  Sep 10 '14 at 10:21
  • @BillyFrost JPQL executed only the ENTITY Related namedQuerys, but i am trying a thing, where i can give MongoDB native find() method and get the result. – Ramesh Manly Sep 10 '14 at 10:36

1 Answers1

1

It makes little sense to do what you're doing. By that I mean you can gain access to the underlying MongoDB "DB" object (that JPA is using) and do things using the native MongoDB API, rather than expecting DataNucleus to invent some artificial query language layered on top of it (this string db.BLAH.find() doesn't exist in the MongoDB native API, instead you do db.getCollection("BLAH") and then impose constraints etc and finally call find() on it). Instead you could try (something like) this

import org.datanucleus.ExecutionContext;
import org.datanucleus.store.NucleusConnection;

ExecutionContext ec = em.unwrap(ExecutionContext.class);
NucleusConnection conn = ec.getStoreManager().getNucleusConnection(ec);
DB db = (DB)conn.getNativeConnection();

Thereafter you have the DB object to use, and after use you should call

conn.close();

to hand it back to JPA (DataNucleus).