Open surendrayadav15 opened 5 years ago
package com.bt.OrientdBNSD.ParseParse1111.beans;
import java.io.FileNotFoundException; import java.io.InputStream;
import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.constructor.Constructor;
import com.esotericsoftware.yamlbeans.YamlException; import com.orientechnologies.orient.object.db.OObjectDatabaseTx;
public class Main {
public static void main(String args[]) throws FileNotFoundException, YamlException{
Main main = new Main();
main.parseYaml();
}
/**
* @param fileName
* @throws FileNotFoundException
* @throws YamlException
* This method will be parsing yaml file and create NetworkServiceDescriptor Object to store in OrientDB
*/
public void parseYaml() throws FileNotFoundException, YamlException{
Yaml yaml = new Yaml(new Constructor(NetworkServiceDescriptor.class));
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("Test.yaml");
NetworkServiceDescriptor nsd = (NetworkServiceDescriptor) yaml.load(inputStream);
System.out.println(nsd);
//DB call
createDOC(nsd);
}
/**
* @param nsd
* get DB connection and store value in OrientDB
*/
private void createDOC(NetworkServiceDescriptor nsd) {
OObjectDatabaseTx db = getDBConnection();
db.getEntityManager().registerEntityClasses("com.bt.OrientdBNSD.ParseParse1111.beans");
db.save(nsd);
db.commit();
}
/**
* @return
* DB Connection created using OObjectDatabaseT
*/
public static OObjectDatabaseTx getDBConnection() {
OObjectDatabaseTx db = new OObjectDatabaseTx("remote:localhost/NSDObjStore").open("root", "root");
return db;
}
}
package com.bt.OrientdBNSD.ParseParse1111.beans;
public class NetworkServiceDescriptor { public TopologyTemplate topology_template;
public TopologyTemplate getTopology_template() {
return topology_template;
}
public void setTopology_template(TopologyTemplate topology_template) {
this.topology_template = topology_template;
}
}
package com.bt.OrientdBNSD.ParseParse1111.beans;
import java.util.Map;
public class TopologyTemplate {
private Map<String,NodeParams> node_templates;
public Map<String, NodeParams> getNode_templates() {
return node_templates;
}
public void setNode_templates(Map<String, NodeParams> node_templates) {
this.node_templates = node_templates;
}
}
package com.bt.OrientdBNSD.ParseParse1111.beans;
import java.util.Map;
public class NodeParams { private String type; private Map<String,Map<String,Object>> interfaces;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public Map<String, Map<String, Object>> getInterfaces() {
return interfaces;
}
public void setInterfaces(Map<String, Map<String, Object>> interfaces) {
this.interfaces = interfaces;
}
}
I am getting following error when trying to persist java object in Orient DB version "3.0.15"
Mar 29, 2019 12:34:05 PM com.orientechnologies.common.log.OLogManager log INFO: Windows OS is detected, 262144 limit of open files will be set for the disk cache. Exception in thread "main" com.orientechnologies.orient.core.exception.OSerializationException: Error serializing object of class class com.bt.OrientdBNSD.ParseParse1111.beans.NodeParams DB name="NSDObjStore" at com.orientechnologies.orient.object.enhancement.OObjectEntitySerializer.serializeObject(OObjectEntitySerializer.java:150) at com.orientechnologies.orient.object.enhancement.OObjectEntitySerializer.typeToStream(OObjectEntitySerializer.java:819) at com.orientechnologies.orient.object.enhancement.OObjectEntitySerializer.multiValueToStream(OObjectEntitySerializer.java:1402) at com.orientechnologies.orient.object.enhancement.OObjectEntitySerializer.typeToStream(OObjectEntitySerializer.java:810) at com.orientechnologies.orient.object.enhancement.OObjectEntitySerializer.toStream(OObjectEntitySerializer.java:1221) at com.orientechnologies.orient.object.enhancement.OObjectEntitySerializer.serializeObject(OObjectEntitySerializer.java:148) at com.orientechnologies.orient.object.enhancement.OObjectEntitySerializer.typeToStream(OObjectEntitySerializer.java:819) at com.orientechnologies.orient.object.enhancement.OObjectEntitySerializer.toStream(OObjectEntitySerializer.java:1221) at com.orientechnologies.orient.object.enhancement.OObjectEntitySerializer.serializeObject(OObjectEntitySerializer.java:148) at com.orientechnologies.orient.object.db.OObjectDatabaseTx.save(OObjectDatabaseTx.java:499) at com.orientechnologies.orient.object.db.OObjectDatabaseTx.save(OObjectDatabaseTx.java:444) at com.bt.OrientdBNSD.ParseParse1111.beans.Main.createDOC(Main.java:39) at com.bt.OrientdBNSD.ParseParse1111.beans.Main.parseYaml(Main.java:33) at com.bt.OrientdBNSD.ParseParse1111.beans.Main.main(Main.java:21) Caused by: java.lang.IllegalArgumentException: Type EMBEDDED must be a multi value type (collection or map) at com.orientechnologies.orient.object.enhancement.OObjectEntitySerializer.multiValueToStream(OObjectEntitySerializer.java:1381) at com.orientechnologies.orient.object.enhancement.OObjectEntitySerializer.typeToStream(OObjectEntitySerializer.java:810) at com.orientechnologies.orient.object.enhancement.OObjectEntitySerializer.multiValueToStream(OObjectEntitySerializer.java:1402) at com.orientechnologies.orient.object.enhancement.OObjectEntitySerializer.typeToStream(OObjectEntitySerializer.java:810) at com.orientechnologies.orient.object.enhancement.OObjectEntitySerializer.multiValueToStream(OObjectEntitySerializer.java:1402) at com.orientechnologies.orient.object.enhancement.OObjectEntitySerializer.typeToStream(OObjectEntitySerializer.java:810) at com.orientechnologies.orient.object.enhancement.OObjectEntitySerializer.multiValueToStream(OObjectEntitySerializer.java:1402) at com.orientechnologies.orient.object.enhancement.OObjectEntitySerializer.typeToStream(OObjectEntitySerializer.java:810) at com.orientechnologies.orient.object.enhancement.OObjectEntitySerializer.multiValueToStream(OObjectEntitySerializer.java:1402) at com.orientechnologies.orient.object.enhancement.OObjectEntitySerializer.typeToStream(OObjectEntitySerializer.java:810) at com.orientechnologies.orient.object.enhancement.OObjectEntitySerializer.toStream(OObjectEntitySerializer.java:1221) at com.orientechnologies.orient.object.enhancement.OObjectEntitySerializer.serializeObject(OObjectEntitySerializer.java:148) ... 13 more