silmeth
silmeth

Reputation: 700

Using morphia’s fromDBObject without DataStore

I am working on an application that directly uses Java MongoDB driver for Mongo queries.

I’d like to use Morphia to map retrieved Documents to my POJOs and vice versa (but I do not want to do queries through Morphia itself).

I am trying to achieve this with Morphia 1.1, however the fromDBObject in this version requires Morphia’s DataStore as an argument (previous versions did without it) – and I do not want to give Morphia actual connection to the database. I am not using references to join data from different collections – so when transforming an already retrieved document to POJO it is not needed to retrieve any additional data from the DB.

Can I achieve this in the version 1.1 (eg. by creating and passing an empty, nonfunctional datastore (how to create it?), or just by passing null)?

If not, I can live with the older (1.0.1) version – but does that make sense?

And if not – what would be the best solution for mapping POJOs to Mongo documents – are there any other, currently maintained, libraries to achieve this?

And, again, if not – what would be the best way to implement this functionality myself? The solution should be as generic as possible regarding document and POJO classes schema, I am OK with annotating my entity classes.

Upvotes: 1

Views: 507

Answers (1)

evanchooly
evanchooly

Reputation: 6233

Did you try passing in null for the Datastore? It's used for resolving any @Referenced fields for the most part. You should be fine just passing null. But as always, "try it and see."

Upvotes: 2

Related Questions