Search code examples
javaignite

Apache Ignite - how to evolve schema/properties of an annotated class


I'm using Apache Ignite with class annotations as described in "Query Configuration by Annotations".

How should we handle class changes? For example what happen if from v1 and v2 of my application I add a new property? Are previous values deserialized? Can I specify a default value?

I cannot find any documentation on this topic. I have tried with a simple use case and seems that new properties are null. How can I handle this?

UPDATE

Following suggestions from @dmagda I have tried to add a property on my class, adding it to the table using ALTER TABLE MYTABLE ADD COLUMN myNewProperty varchar; and then changing it's value using UPDATE MYTABLE SET myNewProperty='myDefaultValue'.
But unfortunately running the abode UPDATE I get the exception: Error: class org.apache.ignite.binary.BinaryObjectException: Failed to unmarshal object with optimized marshaller (state=50000,code=0)

It is possible to update existing records by changing new fields using SQL? How?

UPDATE 2

Solved my problem. It was caused by the fact that my class was written in scala with some scala specific types ('Map', ...). My app connects to Ignite using client mode and so when executing UPDATE from sqlline utility Ignite was unable to deserialize the types. Now I switched my class to be plain POJO and now I'm able to update schema and update data.


Solution

  • Just update your Java class by adding a new field and it will be stored and can be read back without any issue. You might see null as a value of the new field for two reasons:

    • It was not set to any specific value by your application
    • You're reading back from Ignite an old object which was stored before you updated your class and, thus, the new field didn't present there.

    If you need to access the new field using SQL, then use ALTER TABLE command to add the field to the SQL schema.