Coder Social home page Coder Social logo

jkuehn / gorm-mongodb Goto Github PK

View Code? Open in Web Editor NEW
21.0 1.0 15.0 8.38 MB

Grails GORM implementation for the MongoDB document oriented database

Home Page: http://www.grails.org/plugin/mongodb-morphia

License: Apache License 2.0

Groovy 75.76% Java 24.22% Batchfile 0.02%

gorm-mongodb's Introduction

This plugin is no longer maintained. Please consider using the official Grails MongoDB Plugin: https://grails.org/plugin/mongodb

MongoDB GORM plugin for Grails

MongoDB is a scalable, high-performance, schemafree and production ready NoSQL database. This plugin implements the GORM functionality for MongoDB. Under the hood it uses Morphia as a lightweight type-safe library for mapping domain classes to/from MongoDB.

You will find a list of all domain class methods and other information in the User Guide

Built with IntelliJ IDEA and kindly supported with JProfiler

Special thanks to the contributors:

  • Hubert Chang
  • Jesper Zedlitz
  • Alex Duan
  • Alexander Riss
  • Hasan Ozgan
  • Dave Smith

gorm-mongodb's People

Contributors

alexander-riss avatar alexduan avatar davejsmith avatar hz avatar jkuehn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

gorm-mongodb's Issues

Domain.list() return MorphiaIterator when GORM semantics are slightly different

I am new to grails and recently moved from the mongodb plugin to this plugin. I pass a Domain.list() from my controller to gsp file. This plugin returns a MorphiaIterator while the gsp expects something more along the lines of a list. I'm not sure what grails/gorm actually uses but the semantics are different enough that I need to create my own list from the MorphiaIterator.

Runtime Error

Hi,
I'm getting this exception when try to create a simple object with

Document d = new Document(params)

"
URI
/MongoDbCloudDoc/document/create
Class
org.springframework.beans.PropertyBatchUpdateException
Message
Failed properties: Property 'transactionManager' threw exception; nested exception is java.lang.IllegalStateException: Cannot locate GORM API implementation. You either don't have a GORM implementation installed (such as the Hibernate plugin) or you are running Grails code outside the context of a Grails application.
"

I'm configuring my Datasource.groovy like this:

mongodb {
host = 'localhost'
port = 27017
databaseName = 'clouddb'
}

and my domain class have the annotation

@com.google.code.morphia.annotations.Entity

I'm using Grails 2.0.0.M2 and MongoDB 2.0

Thank you!

ps: How can I highlight codes?

Unable to resolve class

With grails 2.4.4 when i try to use the plugin and compile the project, the plugin fails to import all these classes

import com.google.code.morphia.annotations.Transient
import com.google.code.morphia.annotations.Embedded;
import com.google.code.morphia.annotations.Id;
import com.google.code.morphia.annotations.Version;
import org.bson.types.ObjectId
import com.google.code.morphia.annotations.Entity

finally throwing

Error executing plugin mongodb-morphia-0.8.2 script: target/work/plugins/mongodb-morphia-0.8.2/scripts/_Install.groovy

Getting exception "com.mongodb.BasicDBObject cannot be cast to com.mongodb.DBRef"

Hi,
I have a mongo domain class called MyClass, which contains a non-Id member variable called "Long myMember". When I call the GORM method MyClass.findByMyMember(someValue), I get the java.lang.ClassCastException noted in the title. If I change findByMyMember to findAllByMyMember(someValue), it doesn't complain initially and simply returns an object of type com.google.code.morphia.query.MorphiaIterator@284eb041. But, if I now attempt to access it.next(), it once again gives the same exception, for which the stacktrace is below:

java.lang.ClassCastException: com.mongodb.BasicDBObject cannot be cast to com.mongodb.DBRef
at com.google.code.morphia.mapping.ReferenceMapper.readCollection(ReferenceMapper.java:224)
at com.google.code.morphia.mapping.ReferenceMapper.fromDBObject(ReferenceMapper.java:143)
at com.google.code.morphia.mapping.Mapper.readMappedField(Mapper.java:505)
at com.google.code.morphia.mapping.Mapper.fromDb(Mapper.java:484)
at com.google.code.morphia.mapping.Mapper.fromDBObject(Mapper.java:267)
at com.google.code.morphia.query.MorphiaIterator.convertItem(MorphiaIterator.java:66)
at com.google.code.morphia.query.MorphiaIterator.processItem(MorphiaIterator.java:53)
at com.google.code.morphia.query.MorphiaIterator.next(MorphiaIterator.java:48)
at java_util_Iterator$next.call(Unknown Source)

Btw I'm not able to join the Grails User mailing lists as access to new users has been broken for at least a few weeks now, and reporting that issue on IRC and Twitter hasn't helped. Otherwise I would've asked the question there first before opening an issue. Thanks for any help! Let me know if you need more information,

-Sid

Extending Classes raised MultipleId complaint

Environment: Grails 1.3.6, mongodb-morphia-0.6

I have an abstract class, BaseDomain:


abstract class BaseDomain {
    Date dateCreated
    Date lastUpdated
}

Which is extended by Person:


class Person extends BaseDomain {
    String firstName
    String lastName
}

When starting up my Grails app, I get the following error:


adding domain class com.redshoe.live.domain.entity.Person to morphia
2011-02-23 23:02:35,891 [main] ERROR plugins.DefaultGrailsPlugin  - Error processing mongodb domain Artefact > com.redshoe.live.domain.entity.Person: Number of violations: 2
MultipleId complained about com.redshoe.live.domain.entity.Person. : More than one @Id Field found (_id, _id).DuplicatedAttributeNames complained about com.redshoe.live.domain.entity.Person.id : Mapping to MongoDB field name '_id' is duplicated; you cannot map different java fields to the same MongoDB field.

This error only occurs if the superclass also resides within the grails-app/mongo source folder (I tried moving the abstract class out just to check). Unfortunately, that is not a feasible solution for all my classes since I have another class extending Person, and I get the same error.

errorr in the install script

mongodb-morphia-0.8.1/src/groovy/grails/plugins/mongodb/ast/MongoDomainASTTransformation.groovy: 174: Mixing private and public/protected methods of the same name causes multimethods to be disabled and is forbidden to avoid surprising behaviour. Renaming the private methods will solve the problem.
@ line 174, column 3.
private PropertyNode getProperty(ClassNode classNode, String propertyName) {

did it support "unique" save?

hi, I use this plugin now. did it support unique field save only one time?
like this:
class User{
String name;
static constraints = {
name(blank: false, unique: true)
}
}
def user1=new User("myname");
def user2=new User("myname");
user1.save();
user2.save();// the unique field "name" say it can't save, but now it can save, use db.User.find(), show same name, different ObjectId.

(obvious) Don't think this is working with Grails 1.4

I'm fairly new to grails. I was able to install the plugin using grails 1.4, but when I tried to create a domain class I got a compilation error. I then grabbed the source, ran grails upgrade and then grails package-plugin, the result of which was a different exception. Just putting this here so folks know that it's not ready for grails 1.4 just yet.

Trying to use generated scaffolding causes error

| Error 2012-12-11 17:58:19,705 [http-bio-8090-exec-10] ERROR mongodb.MongoDomainClass - Could not get instance from DB
Message: invalid ObjectId [null]
Line | Method
->> 128 | in org.bson.types.ObjectId


| 122 | in ''
| 554 | _checkedId . . . in grails.plugins.mongodb.MongoPluginSupport
| 240 | doCall in grails.plugins.mongodb.MongoPluginSupport$_addStaticMethods_closure13
| 34 | show . . . . . . in mongotest.DummyBController
| 195 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter . . . . in grails.plugin.cache.web.filter.AbstractFilter
| 46 | doFilterInternal in org.grails.jaxrs.web.JaxrsFilter
| 886 | runTask . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
| 908 | run in ''
^ 680 | run . . . . . . in java.lang.Thread

package mongotest

import com.google.code.morphia.annotations.Entity
import grails.plugins.mongodb.ast.TransformationConfiguration

@Entity
@TransformationConfiguration(injectId = true, injectVersion = true)
class DummyB {
    transient mongo // spring bean, dependency injection

    String b
    Date dateCreated
    Date lastUpdated

    static constraints = {
        b nullable: false
    }

    def validate() {
        return true;
    }

    String toString() {
        'DummyB: ' + id + '::' + b
    }
}

There is a dummy validate() function to work around the previous issue I submitted where the validate() function is not found on the domain objects.

Getting an error when trying a simple Domain Class

| Error 2012-12-11 14:41:49,349 [http-bio-8090-exec-10] ERROR errors.GrailsExceptionResolver - IllegalStateException occurred when processing request: [POST] /VektorServices/classB/save - parameters:
b: dfgdfdsf
create: Create
Method on class [mongotest.ClassB] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails correctly.. Stacktrace follows:
Message: Method on class [mongotest.ClassB] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails correctly.
Line | Method
->> 134 | doCall in grails.plugins.mongodb.MongoPluginSupport$_addInstanceMethods_closure3


| 24 | save in mongotest.ClassBController
| 195 | doFilter . . . . in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 46 | doFilterInternal in org.grails.jaxrs.web.JaxrsFilter
| 886 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
| 908 | run . . . . . . in ''
^ 680 | run in java.lang.Thread

package mongotest

import com.google.code.morphia.annotations.Entity
import grails.plugins.mongodb.ast.TransformationConfiguration
import com.google.code.morphia.annotations.Reference

@Entity
@TransformationConfiguration(injectId = true)
class ClassA {
    String foo
    Integer bar

    @Reference
    ClassB b

    Date dateCreated
    Date lastUpdated

    static constraints = {
    }
}

package mongotest

import com.google.code.morphia.annotations.Entity
import grails.plugins.mongodb.ast.TransformationConfiguration

@Entity
@TransformationConfiguration(injectId = true)
class ClassB {
    String b
    Date dateCreated
    Date lastUpdated

    static constraints = {
        b nullable: false
    }
}

Advanced Querying using this plugin

Hi,

I have been wanting some information on how to do some more advanced queries on the Mongo DB using the Grails Morphia plugin. I want to use query operators like $where, $or, etc.

I tried doing something like this but it didn't work,

def list = TestDomain.findAll(["where": "this.obj1.obj2.obj3 == 'dud' || this.obj1.obj2 == 'notdud' "], [max:100, validation: "false"])

But it seems to give me a validation error. Nevertheless I'm still not sure if this is the correct syntax or not. Haven't found anything on the net about this.

In the Morphia Library, it appears that you can do a DomainObject.where() and pass the Java Script condition as an argument. I really need this urgently as I won't be able to use Morphia without having OR / WHERE query options in my application.

Could you please let me know how this can be done from within the Grails Morphia Plugin?

Cheers,

Varun

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.