You have to include Person class in binary configuration:

            IIgnite ignite = Ignition.Start(new IgniteConfiguration
            {
                SpringConfigUrl = @"F:\Visual Studio
2015\Projects\CreateCluster\CreateCluster\my-file.xml",
                BinaryConfiguration = new
BinaryConfiguration(typeof(Person))
            });

Also you have different cache names in config (personCache) and code
(Mycache).
Use GetCache instead of GetOrCreateCache to make sure that cache is started
from XML config.



On Fri, Mar 24, 2017 at 11:32 AM, kavitha <kavithamr...@gmail.com> wrote:

> Hi,
>
> I am using following code to load data in Ignite cluster. But I got below
> error.
>
> my-file.xml code:
> <?xml version="1.0" encoding="UTF-8"?>
>
> <beans xmlns="http://www.springframework.org/schema/beans";
>        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>        xsi:schemaLocation="http://www.springframework.org/schema/beans
>         http://www.springframework.org/schema/beans/spring-beans.xsd";>
> <bean id="ignite.cfg"
> class="org.apache.ignite.configuration.IgniteConfiguration">
>   <property name="odbcConfiguration">
>     <bean class="org.apache.ignite.configuration.OdbcConfiguration"/>
>   </property>
>  <property name="cacheConfiguration">
>         <list>
>             <bean
> class="org.apache.ignite.configuration.CacheConfiguration">
>                 <property name="name" value="personCache"></property>
>                                 <property name="queryEntities">
>                     <list>
>                         <bean class="org.apache.ignite.cache.QueryEntity">
>                             <property name="keyType"
> value="java.lang.Long"></property>
>                             <property name="valueType"
> value="ignite.myexamples.model.Person"></property>
>                             <property name="fields">
>                                 <map>
>                                     <entry key="id"
> value="java.lang.Long"></entry>
>                                     <entry key="name"
> value="java.lang.String"></entry>
>                                     <entry key="orgId"
> value="java.lang.Long"></entry>
>                                     <entry key="salary"
> value="java.lang.Integer"></entry>
>                                 </map>
>                             </property>
>                         </bean>
>                     </list>
>                 </property>
>             </bean>
>         </list>
>     </property>
>
>     <property name="peerClassLoadingEnabled" value="true"></property>
>
>         </bean>
> </beans>
>
> class Person :IBinarizable
>     {
>         public long id { get; set; }
>         public long orgId { get; set; }
>         public string name { get; set; }
>         public int salary { get; set; }
>
>         public Person(long a, long b, string c, int d)
>         {
>             id = a;
>             orgId = b;
>             name = c;
>             salary = d;
>         }
>         public void WriteBinary(IBinaryWriter writer)
>         {
>             var rawWriter = writer.GetRawWriter();
>
>             rawWriter.WriteString(name);
>             rawWriter.WriteInt(salary);
>         }
>
>         public void ReadBinary(IBinaryReader reader)
>         {
>             var rawReader = reader.GetRawReader();
>
>             name = rawReader.ReadString();
>             salary = rawReader.ReadInt();
>         }
>
>     }
>
>  class Program
>     {
>         static void Main(string[] args)
>         {
>             Person obj = new Person(1,1000, "John",20000);
>             Person obj1 = new Person(2,2000, "Smith", 38000);
>
>             IIgnite ignite = Ignition.Start(@"F:Visual Studio
> 2015\Projects\CreateCluster\CreateCluster\my-file.xml");
>             var cache = ignite.GetOrCreateCache<int, Person>("Mycache");
>             cache.Put(1,obj);
>             cache.Put(2,obj1);
>          }
>    }
> }
>
>
> Error: An unhandled exception of type
> 'Apache.Ignite.Core.Binary.BinaryObjectException' occurred in
> Apache.Ignite.Core.dll
>
> Additional information: Unsupported object type [type=CreateCluster.Person,
> object=CreateCluster.Person].
>
> Specified type can not be serialized by Ignite: it is neither
> [Serializable], nor registered in IgniteConfiguration.BinaryConfiguration.
>
>
>
> --
> View this message in context: http://apache-ignite-users.
> 70518.x6.nabble.com/Load-data-to-cache-tp11394p11414.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>

Reply via email to