Non è possibile ottenere il plugin GORM MONGODB per salvare un nuovo record, anche con un colore esplicito

StackOverflow https://stackoverflow.com//questions/9626172

Domanda

Cosa so: MONGOD è in esecuzione, il database esiste, la collezione esiste, posso fare inserti utilizzando la console mongodb e una connessione all'istanza Mongod è fatta da Grails (cioè posso interrogare e così via). .

altri dettagli: Grails 2.01, Plugin mongodb 1.0.0 RC4, Hibernate Plugin 2.01, MongoDB 2.0.3

class Node {
    static mapWith = "mongo"

    static constraints = {
    }

    ObjectId id
    Integer someId //someId can be null or just non-existent
    String name
}
.

Che cosa non funziona: non riesco a inserire alcun dato tramite GORMO, anche quando impostare esplicitamente lavare a FLUSH su TRUE.

def n = com.company.project.Node(name: "test")
n.save(flush:true)
.

Ho anche provato questo nella console Grails, ma non c'è un messaggio di errore.C'è qualcosa che ho fatto sbagliato?

È stato utile?

Soluzione

I'm new to Grails so someone else may or may not correct me. Anyways the issue is that the Mongodb GORM plugin by default doesn't allow null values of any fields that you specify in Mongodb domain classes.

As of now I'm not sure how to override this behavior, but I will update this if I ever figure it out.

Altri suggerimenti

Have you tried to make your properties nullable? Something like this:

static constraints = 
{
   someId nullable: true
}

Execute validate() method before save and take a look on the result, most probably there is some constraint error of which you may not know.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top