yojimbo87 / OrientDB-NET.binary

C#/.NET binary driver for OrientDB
MIT License
21 stars 19 forks source link

TypeMapperError when inserting object #44

Closed degustator closed 9 years ago

degustator commented 9 years ago

I'm getting TypeMapper exception when trying to persist object that is of class Event. Event class not just simple class, it has subclasses as properties.

What kind of fields cannot be persisted to Orient using OrientDB-NET.binary?

  using (ODatabase database = new ODatabase("ntt"))
        {

            // prerequisites

            //database.Create.Class<Event>().Run();

            StreamReader reader = new StreamReader(@"event1.json");
            string json = reader.ReadToEnd();
            reader.Close();

            Event sample_event = Event.Deserialize(json);

            Event insertedDocument = database
                .Insert(sample_event)
                .Run<Event>();

        }

System.TypeInitializationException was unhandled HResult=-2146233036 Message=The type initializer for 'Orient.Client.Mapping.TypeMapper1' threw an exception. Source=Orient.Client TypeName=Orient.Client.Mapping.TypeMapper1 StackTrace: at Orient.Client.Mapping.TypeMapper1.get_Instance() in c:\Temp\OrientDB\Orient.Client\Mapping\TypeMapper.cs:line 30 at Orient.Client.Mapping.ClassFieldMapping2.MapToDocument(TTarget typedObject, ODocument document) in c:\Temp\OrientDB\Orient.Client\Mapping\ClassFieldMapping.cs:line 21 at Orient.Client.Mapping.FieldMapping1.MapToDocument(Object typedObject, ODocument document) in c:\Temp\OrientDB\Orient.Client\Mapping\FieldMapping.cs:line 51 at Orient.Client.Mapping.TypeMapper1.ToDocument(Object genericObject) in c:\Temp\OrientDB\Orient.Client\Mapping\TypeMapper.cs:line 151 at Orient.Client.Mapping.ClassFieldMapping2.MapToDocument(TTarget typedObject, ODocument document) in c:\Temp\OrientDB\Orient.Client\Mapping\ClassFieldMapping.cs:line 21 at Orient.Client.Mapping.FieldMapping1.MapToDocument(Object typedObject, ODocument document) in c:\Temp\OrientDB\Orient.Client\Mapping\FieldMapping.cs:line 51 at Orient.Client.Mapping.TypeMapper1.ToDocument(Object genericObject) in c:\Temp\OrientDB\Orient.Client\Mapping\TypeMapper.cs:line 151 at Orient.Client.ODocument.ToDocument[T](T genericObject) in c:\Temp\OrientDB\Orient.Client\API\Types\ODocument.cs:line 298 at Orient.Client.Protocol.SqlQuery.Insert[T](T obj) in c:\Temp\OrientDB\Orient.Client\Protocol\Query\SqlQuery.cs:line 76 at Orient.Client.OSqlInsert.Insert[T](T obj) in c:\Temp\OrientDB\Orient.Client\API\Query\OSqlInsert.cs:line 43 at Orient.Client.ODatabase.Insert[T](T obj) in c:\Temp\OrientDB\Orient.Client\API\ODatabase.cs:line 115 at OrientDBTest.Program.Main(String[] args) in c:\TFS\NGP\NTT\Main\Auxillary\OrientDBTest\Program.cs:line 51 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: System.NotImplementedException HResult=-2147467263 Message=No mapping implemented for type Nullable1 Source=Orient.Client StackTrace: at Orient.Client.Mapping.TypeMapper1..ctor() in c:\Temp\OrientDB\Orient.Client\Mapping\TypeMapper.cs:line 105 at Orient.Client.Mapping.TypeMapper1..cctor() in c:\Temp\OrientDB\Orient.Client\Mapping\TypeMapper.cs:line 29 InnerException:

GoorMoon commented 9 years ago

@degustator , Please open issue in official repository of OrientDB driver https://github.com/orientechnologies/OrientDB-NET.binary Can you please post Event class also ?

degustator commented 9 years ago

OK, I think we can close this item.

I tried to post the Event structure that has some MongoDB specific fields.

degustator commented 9 years ago

OK, I will reopen item :(

I simplified the structure of Event and now its defined the same code

using Orient.Client; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace OrientDBTest { class Program {

    class Event
    {
        public String hid { get; set; }
        public String platform { get; set; }
        public String service { get; set; }
        public String date { get; set; }
        public Payload payload { get; set; }

    }
    class Payload
    {
        public String stuff1 { get; set; }
        public String stuff2 { get; set; }
    }

    static void Main(string[] args)
    {
        Console.WriteLine("Orient test");
        OClient.CreateDatabasePool(
            "127.0.0.1",
            2424,
            "ntt",
            ODatabaseType.Graph,
            "root",
            "root",
            10,
            "ntt"
        );

        using (ODatabase database = new ODatabase("ntt"))
        {

             //prerequisites

            database.Create.Class<Event>().Run();
            database.Create.Class<Payload>().Run(); /*Should I create substructure as class?*/

            Event sample_event = new Event() { hid = "sadsad", date = "sadfsad", service = "sadsadsada", platform = "sfdsafsd", payload = new Payload() {  stuff1 = "sdsad",stuff2 ="sdfsdfasdf"} };

            Event insertedDocument = database
                .Insert(sample_event)
                .Run<Event>();

        }
    }
}

}

Now I get exception System.NullReferenceException was unhandled HResult=-2147467261 Message=Object reference not set to an instance of an object. Source=Orient.Client StackTrace: at Orient.Client.Mapping.NamedFieldMapping1.MapToObject(ODocument document, TTarget typedObject) in c:\Temp\OrientDB\Orient.Client\Mapping\FieldMapping.cs:line 63 at Orient.Client.Mapping.FieldMapping1.MapToObject(ODocument document, Object typedObject) in c:\Temp\OrientDB\Orient.Client\Mapping\FieldMapping.cs:line 46 at Orient.Client.Mapping.TypeMapper1.ToObject(ODocument document, T typedObject) in c:\Temp\OrientDB\Orient.Client\Mapping\TypeMapper.cs:line 138 at Orient.Client.Mapping.ClassFieldMapping2.MapToObject(ODocument document, TTarget typedObject) in c:\Temp\OrientDB\Orient.Client\Mapping\ClassFieldMapping.cs:line 15 at Orient.Client.Mapping.FieldMapping1.MapToObject(ODocument document, Object typedObject) in c:\Temp\OrientDB\Orient.Client\Mapping\FieldMapping.cs:line 46 at Orient.Client.Mapping.TypeMapper1.ToObject(ODocument document, T typedObject) in c:\Temp\OrientDB\Orient.Client\Mapping\TypeMapper.cs:line 138 at Orient.Client.ODocument.ToObject[T](T genericObject, String path) in c:\Temp\OrientDB\Orient.Client\API\Types\ODocument.cs:line 304 at Orient.Client.ODocument.To[T]() in c:\Temp\OrientDB\Orient.Client\API\Types\ODocument.cs:line 279 at Orient.Client.OSqlInsert.Run[T]() in c:\Temp\OrientDB\Orient.Client\API\Query\OSqlInsert.cs:line 120 at OrientDBTest.Program.Main(String[] args) in c:\TFS\NGP\NTT\Main\Auxillary\OrientDBTest\Program.cs:line 55 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException:

Where can be the problem? We cannot persist multilevel objects?

degustator commented 9 years ago

Just wondering will this issue be reviewed? Or I should create new one?

May be someone can just give shot comment is this a bug or I'm doing something wrong?

GoorMoon commented 9 years ago

@degustator , Tomas doesn't maintaining this driver any more and code with improvement moved to the another repository https://github.com/orientechnologies/OrientDB-NET.binary please download latest code from repository and check the issue. If still have error please open issue here https://github.com/orientechnologies/OrientDB-NET.binary/issues And will be review this.

yojimbo87 commented 9 years ago

Sorry for the late response. As @GoorMoon said I no longer maintain this repository and development now takes place in https://github.com/orientechnologies/OrientDB-NET.binary repository. I will update readme to avoid confusion in the future.

degustator commented 9 years ago

OK, it works now. Thanks