Hi Andry, It is look like a mistake:
cache.put(1, new TestVal("old")); TestVal oldVal = cache.get(1); oldVal.val = "new"; cache.put(1, oldVal); You need create new object always. Try to do like this: cache.put(1, new TestVal("old")); cache.put(1, new TestVal("new")); Otherwise you can to get strange behavior, in particular if you are using copyOnRead - false. On Fri, Nov 4, 2016 at 4:03 PM, Andry <andrykoro...@gmail.com> wrote: > Hi, > > We're trying to use Continuous Query to handle updates on existing object, > but it looks like as oldValue in Update event is working incorrectly. > > Example of our usage: > > public class TestContinuousQueryUpdateEvent { > > private static class TestVal { > public String val; > > public TestVal(String val) { > this.val = val; > } > > @Override > public String toString() { > return val; > } > } > > public static void main(String[] args) throws Exception { > try (Ignite ignite = > Ignition.start("examples/config/example-ignite.xml")) { > try (IgniteCache<Integer, TestVal> cache = > ignite.getOrCreateCache("test")) { > ContinuousQuery<Integer, TestVal> qry = new > ContinuousQuery<>(); > > qry.setRemoteFilterFactory(FactoryBuilder.factoryOf(remoteFilter())); > > qry.setLocalListener(evts -> { > for (CacheEntryEvent<? extends Integer, ? extends > TestVal> e : evts) > System.out.println("Local Listener: Event Type = " > + > e.getEventType() + ", Old val = " + e.getOldValue() + ", New val = " + > e.getValue()); > }); > > cache.query(qry); > > cache.put(1, new TestVal("old")); > > TestVal oldVal = cache.get(1); > oldVal.val = "new"; > > cache.put(1, oldVal); > > sleep(1000); > } finally { > ignite.destroyCache("test"); > } > } > } > > private static CacheEntryEventSerializableFilter<Integer, TestVal> > remoteFilter() { > return e -> true; > } > } > > Output: > Local Listener: Event Type = CREATED, Old val = null, New val = old > Local Listener: Event Type = UPDATED, Old val = new, New val = new > > We expected that oldValue will return actually saved object rather then > reference to object we have modified in our code. > > Please advise how should we deal with this. > > > > > > > -- > View this message in context: http://apache-ignite-users. > 70518.x6.nabble.com/Problem-with-v-for-listening-updates-tp8709.html > Sent from the Apache Ignite Users mailing list archive at Nabble.com. > -- Vladislav Pyatkov