zella
zella

Reputation: 4685

How add embedded map to record with sql in OrientDb

I try to add embedded map to record:

UPDATE #12:6941 set fieldWithEmbeddedMap ={
    "1": {
        "@type": "d",
        "@version": 0,
        "@class": "myClass",
        "myFiled": "ok"
    },
    "2": {
        "@type": "d",
        "@version": 0,
        "@class": "myClass",
        "myFiled": "ok"
    }
}

But result is

{"1":"#17:9","2":"#17:10"}

What is correct syntax to set embedded field?

Upvotes: 1

Views: 1210

Answers (1)

Alessandro Rota
Alessandro Rota

Reputation: 3570

I have created a class with the property name(string) and fieldWithEmbeddedMap(embeddedMap)

enter image description here

I have create a record of type Class2

insert into class2(name) values ("Alessandro")  // 14:0

and after I have used your code

UPDATE #14:0 set fieldWithEmbeddedMap ={
    "1": {
        "@type": "d",
        "@version": 0,
        "@class": "myClass",
        "myFiled": "ok"
    },
    "2": {
        "@type": "d",
        "@version": 0,
        "@class": "myClass",
        "myFiled": "ok"
    }
}

The result is the following

enter image description here

Hope it helps.

EDIT

Java code

Map<String, Object> myEntries = new HashMap<String, Object>();
myEntries.put("key1",1);
myEntries.put("key2",2);
myEntries.put("key3",3);

ODocument doc = new ODocument("Test");
doc.field("mymap", myEntries, OType.EMBEDDEDMAP);
doc.save();

From Studio

enter image description here

enter image description here

Upvotes: 1

Related Questions