jkuehn / gorm-mongodb Goto Github PK
View Code? Open in Web Editor NEWGrails GORM implementation for the MongoDB document oriented database
Home Page: http://www.grails.org/plugin/mongodb-morphia
License: Apache License 2.0
Grails GORM implementation for the MongoDB document oriented database
Home Page: http://www.grails.org/plugin/mongodb-morphia
License: Apache License 2.0
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.
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.
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) {
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.
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?
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
| 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.
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
| 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
}
}
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.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.