morphia

Are persistence annotations in domain objects a bad practice?

被刻印的时光 ゝ 提交于 2020-08-21 01:59:40
问题 I realize that persistence frameworks such as Morphia and Hibernate rely on annotations on domain objects to do their magic. At some level, it seems to me that this is inserting persistence concerns into the domain layer which is something we're supposed to strive to avoid. Is this something that I should try to dodge by perhaps using an external configuration file or maybe separate DTOs from the domain model? Or is this little leak between the persistence and domain layers generally regarded

Aggregation by date in Morphia

限于喜欢 提交于 2020-01-17 02:50:07
问题 I'm trying to migrate a PostgreSQL-based application to MongoDB. I'm using Morphia to connect to MongoDB. In my app I have this query to get a list of measurements with Hibernate: ... jpq = jpq.from(qm) .where(qm.parameter.eq(parameter)); jpq = jpq.where(qm.dateTime.between(startDate, endDate)); ... case MINUTE: jpq = jpq.groupBy(qm.dateTime.minute()); case HOUR: jpq = jpq.groupBy(qm.dateTime.hour()); case DAY: jpq = jpq.groupBy(qm.dateTime.dayOfMonth()); case MONTH: jpq = jpq.groupBy(qm

MongoDB using much memory

余生颓废 提交于 2020-01-15 08:14:03
问题 Im tryin to migrate a mysql table to mongodb. My table has 6 million entries. Im using java with morphia. When i save about 1,2 million my memory is almost all consumed. I've read that mongo store the data in memory and after save in disk. Is it possible to send something like a commit to free some amount of memory? 回答1: 1) In terms of durability, you can tell the MongoDB java driver (which Morphia is using), which strategy to use, see https://github.com/mongodb/mongo-java-driver/blob/master

MongoDB using much memory

若如初见. 提交于 2020-01-15 08:13:52
问题 Im tryin to migrate a mysql table to mongodb. My table has 6 million entries. Im using java with morphia. When i save about 1,2 million my memory is almost all consumed. I've read that mongo store the data in memory and after save in disk. Is it possible to send something like a commit to free some amount of memory? 回答1: 1) In terms of durability, you can tell the MongoDB java driver (which Morphia is using), which strategy to use, see https://github.com/mongodb/mongo-java-driver/blob/master

ClassCastException using Morphia

这一生的挚爱 提交于 2020-01-07 04:48:08
问题 I'm trying to get a collection of MongoDB and convert the records into javabeans using Morphia, but when I try to get the collection of objects (see below in App code), a cast error appears: Exception in thread "main" java.lang.ClassCastException: com.mongodb.BasicDBObject cannot be cast to com.homework.Score Document { "_id" : 19, "name" : "Student 01", "scores" : [ { "type" : "exam", "score" : 44.51211101958831 }, { "type" : "quiz", "score" : 0.6578497966368002 }, { "type" : "homework",

Morphia - Query based on a subdocument

社会主义新天地 提交于 2020-01-06 08:36:11
问题 I have a mongo collection which has documents which look like below : { "_id" : ObjectId("9873214jkhdkfjdsf8324"), "nm" : "test", "sts" : 1, "updby" : NumberLong(0), "tags" : [ { "name" : "women", "rank" : 1, "type" : 3 }, { "name" : "men", "rank" : 1 }, { "name" : "clothing", "rank" : 2, "type" : 1 } ] } I want to query the collection such that I want all the documents which have "name": "women" and "type" : 3 inside the tags subdocument of each document which is returned. I know that the

What is the intended behavior of Datastore.save() when handed an Iterable of objects?

て烟熏妆下的殇ゞ 提交于 2020-01-06 05:47:05
问题 I am debugging a bizarre situation involving MongoDB and two programs. The MongoDB installation in question is initially empty and is a toy deployment. There are two programs. One uses Morphia. The other does not. The non-Morphia-using program inserts a record into a Service collection in a foo-bar database like so: mongo << EOF db.getSiblingDB("foo-bar").getCollection("Service").replaceOne( { "service_name" : "argle-bargle" }, { "_id" : "argle-bargle", "className" : "com.foo.Service",

Groovy could not find matching constructor?

拟墨画扇 提交于 2020-01-05 07:51:12
问题 Please note: although this question mentions Mongo it is surely a pure Groovy question at heart. My MyApp#bootstrap method: def bootstrap(AppConfiguration config) { String h = config.dbHost String p = config.dbPort println "Mongo is at: ${h}:${p}." dao = new MongoDao(host: h, port: p) } My MongoDao class (snippet): class MongoDao implements BasicDao { String dbName Mongo mongo String host String port Morphia morphia Datastore datastore MongoDao(String host, String port) { this.dbName = "db

Morphia - Class not found defined in dbObj

强颜欢笑 提交于 2020-01-05 05:22:40
问题 I'm having a rather interesting issue. When attempting to load a model from a Mongo instance, Morphia throws the following error: [22:17:13 WARN]: Class not found defined in dbObj: java.lang.ClassNotFoundException: me.mattrick.test.storage.TestStat at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[?:1.8.0_101] at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[?:1.8.0_101] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) ~[?:1.8.0_101] at java.lang

Morphia/MongoDB: Accessing “embedding” object from an @Embedded object

为君一笑 提交于 2020-01-04 05:54:59
问题 I have a Morphia schema similar to this one: @Entity class BlogEntry { @Embedded List<BlogComment> comments } @Embedded class BlogComment { String content Long authorId } (code above just for illustration) I'm trying to get a specific BlogComment in order to update it with new content. I have the corresponding BlogEntry object available, and I have the authorId, which let's say for the purposes of this question that these two together are sufficient to uniquely identify the correct