I am using hibernate OGM to talk to my MongoDB instance. I had to get a list of all the products with category "abc"
. I am using the native query approach to achieve this as following:
String stringQuery = "db.Message.find({'CATEGORY':'" + category + "})";
Query query = entityManagerProvider.get().createNativeQuery(stringQuery, Product.class);
productList = query.getResultList();
I am not sure if it is the right approach to do this as I see a too much hard coding (look at the collection name). Can I use the .find()
method to achieve the same thing?
We are using vertx server with gradle as building tool.